Assigning Variable To Part Of Workbook Name?

Dec 22, 2011

Ive wrote some code that goes into a workbook. This code then opens up a "master" workbook which has 18 blank tabs in it and then proceeds to open up 18 other named workbooks one at a time and copy some date from these workbooks to the master (i.e workbook 1's data goes to the master workbook on tab "1".)

I have this working no problem but here is my snag.

The workbook name changes every week to correspond with the date (i.e 1_14DEC2011.xls then 1_21DEC2011.xls).

Ideally id like to be able to create a variable for the latter half of the filename so that i can apply this variable to each filepath but i cant quite get it to work.

A small sample of my code is below (and yes i know it is very blunt but so is my knowledge at this stage!)

Code:
Sub collate()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

[Code]....

View 2 Replies


ADVERTISEMENT

Assigning Variable As Workbook

May 15, 2014

So I have a macro that is saving new excel files based on month and year. I want to assign a variable but I keep getting an error.

Here's what I have:

***********
Sub AssignVariables()
Dim Rebates as Workbook
Dim Master as Workbook
Dim month as string

[Code]....

The last two lines are the errors. I want to type in:

Rebates.Activate
Master.Activate

But the error occurs as it gets to the last two lines. By the way, all these two documents are open.

View 4 Replies View Related

Opening Workbook And Assigning Variable

Jul 14, 2014

I am trying to open a workbook, assign it a variable and use that variable later. here is what i have

[Code] ......

When I try to activate it later on in another procedure using:

[Code] copy to clipboard

I receive an "Automation Error"

I have tried declaring it as a public variable, even a global variable and cannot get this to work.

All I'm really wanting to do is open a workbook (where the name will change depending on the book being opened), assign that workbook a variable name, and use it later in the code.

View 7 Replies View Related

Assigning A Variable And Pasting Variable To Last Unused Column

Nov 19, 2008

to assign a variable to equal a Constant variable, then I need to find the last unused row on the worksheet, then paste that variable down the column (1-12200 or so rows). I also need to assign Strings for the first two Rows in the target column.

View 14 Replies View Related

Variable Not Assigning Correctly

Oct 31, 2006

The relevant code is below. I can post it all if necessary -- it's about 30 lines though. Can anyone recognize what the problem might be?

MsgBox "vSh " & vSh & " vOp " & vOp & "vCash " & vCash
vCash = vSh * vOp
MsgBox "vCash " & vCash

The MsgBox's are merely for debugging. When the code above runs, the first MsgBox I receive states similar to:
"vSh 14.238964 vOp 45.23 vCash 1000"
The second MsgBox, from after the multiplication, states:
"vCash 1000"

For some reason the vCash variable just will not set. At the beginning of the code, I declared each variable as Dim var, meaning as a variant, and whenever I debug by halting during a MsgBox display, each of the variables appear to be the same types: Variant/Double.

View 6 Replies View Related

Assigning A Formula To A Variable

Feb 13, 2007

G:G contains a list of integars, though some cells are blank; lets say 75 of the 100 cells in data range are < 0. I want a macro which copies a range where the number of rows = the number of values in G:G. my Macro:

Sub myMacro()
Dim rowRange As Integer
rowRange = Count("G:G")
End Sub

This, as you guessed, comes back with an error. Sub or Function not defined. Anyone the proper syntax for assigning a formula to a variable?

View 5 Replies View Related

Assigning Formula To Variable Inside VBA?

Feb 22, 2013

I tried to count rows from one sheet and to put this value as counter in VBA For-Next loop.

VB:
Sub Copy_ID()
'
' Copy_ID Macro

[Code]...

It ends with "Invalid qualifier" error on the counter.Formula line. I attached sample excel with macro that I listed here.

View 5 Replies View Related

Assigning A Variant Variable To An Integer

Jun 2, 2009

I am assigning the result of a vlookup to a variable that is defined as Variant. I then need to use that variable in a calculation.

View 5 Replies View Related

Assigning Current Region To A Variable

Dec 7, 2009

I’m attempting designate the cell which will then determine the start of the current region, to be copied and pasted to another sheet. I’m receiving an “ERROR 1004” , Method Range of object_ Worksheet Failed.

View 4 Replies View Related

Assigning A Variable To An Unknown Cell

Dec 27, 2006

I'm attempting to create a macro that will look at the total in column (K) and send an e-mail to two different addresses, depending on the amount. If the amount is over $10,000 then one address (over@macro.com) if under, then the other (under@macro.com)

My main problem is that I never know what cell the total is going to be in.

I currently have all quotes going back to the person that sent in the request, no matter what the amount. Their e-mail is in the sheet.

So what I think I need to do, is find the last cell in column K with data and assign it a variable. If that variable is over $10,000 then I can send the e-mail to a hard coded address. If it's over, I just use my original code.

View 9 Replies View Related

Assigning Listbox Members To Variable

Jul 3, 2009

I would like to assign listbox members to a public variable (quite the opposite of what you normally do). I receive the error message "type mismatch".


Public MemberLB as Variant
Public Sub ListBoxTest()
n = ListBox_target.ListCount
For iCnt = 1 To n
MemberLB(iCnt) = ListBox_target.List(iCnt - 1)
Next iCnt
End Sub

View 9 Replies View Related

Assigning Variable Values To Letters In A Table

Jul 20, 2007

I have a formula which assigns a points score to letters in a range and adds them up. In the example below F=0, P=6, M=12 & D=18. =IF( COUNTIF(AT5:BE5,"="""),"",SUM(COUNTIF(AT5:BE5,"=F")*0,COUNTIF(AT5:BE5,"=P")*6,COUNTIF(AT5:BE5,"=M")*12,COUNTIF(AT5:BE5,"=D")*18)). Thus if F, P, M & D were in cells A1:D1 the result would be 0+6+12+18=36.

My aim is to be able to customise the values of F, P, M & D, using a table and a cell value. See the table below, where the first number in each row represents a cell value which the user enters into BH1, the second, third, fourth and fifth numbers represents the values assigned to the letters F, P, M & D.


10 0 1 2 3
30 0 3 6 9
60 0 6 12 18
90 0 9 18 27
120 0 12 24 36

Some examples of expected output: user enters 10 into BH1 and then enters F, P, M & D in cells A1:D1 the result would be 0+1+2+3=6. user enters 90 into BH1 and then enters F, P, M & D in cells A1:D1 the result would be 0+9+18+27=54.

View 4 Replies View Related

Evaluating List Of Similar Names And Assigning Common To Variable?

Sep 17, 2013

I am working on a customer report template that generates our customers reports and will send them out automatically.

This issue I have now is that the system that generates the raw data for these reports only lists the Customers name in a column with an entry for each line of data, the thing is though that the system has lots of variations of the customers name, even more so if that customers has different departments.

What I need to do is from this list of customer names, I need to automatically figure out what the "common" name is or main name so to speak, and then make a variable using the correct full name, which will be used later on in the code to import correct logos, and direct the reports to the correct people.

Here is a quick example of what data we get raw from the system:

Customer Name:
John Build
Johns Buildings
Johns Ltd Building
Johns Plumbing Department
Glass Doors Ltd A Department of Johns Buildings
Johns Building Corporation
Hole In One Golf Range

This is just an example, we have thousands of clients, so the length, number of words etc can change alot. Ideally I from a list similar to that I would get a full proper result of "Johns Buildings Ltd" for example, this would then be in a variable to be used in code from then on to reference doing certain things with the reports of Johns Buildings Ltd.

You'll notice there is one name "Hole In One Golf Range" that seems to have no relation at all, this is correct, ideally I would also like to build in some error checking into the code, so that rows like that that have nothing to do with the others would get deleted.

So how would you amazing VBA gurus go about working with data like this? I'd prefer a more general answer with explainations that just straight code, as I'm sure I will have to adapt the hell out of it for it to be useful in context.

View 9 Replies View Related

Assigning Excel Range To Variable And Then Paste It In Outlook Message Box

Jul 19, 2012

I am writing a code wherein I want to assign specific excel range to a declared variable and then paste this excel in outlook message ody but I am finding difficulty in assigning that range to variable " brng"

I think code is right and issue is there in excel setting.

Code:
Sub mailer()
'
'
'
Dim Ash As Worksheet
Dim brng As Range
Dim OutApp As Object
Dim OutMail As Object
'Windows("Copy of FF RPL REPORT_JULY").Activate

[Code] .......

View 1 Replies View Related

Reference Row With Variable As Part Of

Sep 1, 2007

Dim vCriteria3 As String
vCriteria3 = ActiveCell.Text
Sheets("CUSTOMER OVR REVIEW").Select
Rows("25:25").Select
Selection.Copy
Rows("26:" & vCriteria3).Select
ActiveSheet.Paste

it hits the

Rows("26:" & vCriteria3).Select

and crasses with a "incorrect type" mesage. am i storing this into memory incorrectly? how do i fix it? the function is intended to use a variable to paste over x amount of rows.

View 5 Replies View Related

Using Variable In Cell Formula As Part Of For Next

Aug 13, 2009

I have 2 sheets, Sheet1 and Sheet2. I want to populate Sheet2 Column B with a formula which will reference Column B of sheet1 so that on each iteration of the For..Next, the cell being referenced in the formula will change. So if i = 5, I'd like the cell to be populated with the formula =Sheet1!B5

View 4 Replies View Related

Searching Cells That Contain Part Of Variable

Jul 3, 2014

I am trying to get the following equation to search for cells that contains the term 3R. The issue is I have several different 3R formations as follows and want it to count all of them.

3R
3R FIB
3R S Nasty
3R S Nasty FIB

This is what I am currently using but I want it to be more detailed. Where my search is for everything on 1st down with 10 yards to go in a 3R formation.

=SUMPRODUCT(--(C2:C350=1),--ISNUMBER(MATCH(Criteria,{10},0)),--(H2:H350="3R"))

23
20
1
10
-19
R
Run
PISTOL HVY
3R

[Code] .......

View 2 Replies View Related

Parse Out Part Of Variable For Save As

May 8, 2008

I found a thread that is very much similiar to what I tried to achieve that is to save 110 files into CSV file format here Save Multiple Files In Folder As Text Format.

May I know what changes should I make to this code in order to save it into CSV file format?

ActiveWorkbook.SaveAs targetFolder & Left(aFile, Len(aFile) - 4) _
& ".txt", xlTextMSDOS

View 3 Replies View Related

How To Generate Brand Name From Part Decsription Variable

Jan 6, 2008

I have following part number , And i like to know how to write code to pick the brand name.

Left col is the data i have and code that generate the brand name....

View 9 Replies View Related

Open File With Variable Path & Part Name

Feb 27, 2008

1 I need to open a csv file in order to use data in it at location "C:BarkingEMCIN" to input into an xls spreadsheet. I then need to use the info from the xls spreadsheet along with other info input by users to produce another .csv and it be deposited at "C:BarkingEMCOUT"

The name of the file at "C:BarkingEMCIN" will change everyday or even multiple times a day and be in the format "AVA_DA_260208_BPL_EDF_001.CSV" "AVA DA " will remain the same "260208" will be todays date the next 2 will be interchangeable depending on requirements and use BPL EDF and SSE will be interchangeable depending on requirements and 001 will be the version whcih will be changable. _ underscores will be used as seperators

They will then be save in the format "NOM_DA_260208_BPL_EDF_001.CSV" using the same prinipals as before but automatically saving as the next available when needed with a prompt to tell the user what it will be

View 5 Replies View Related

Remove Space Between Variable And Constant Part Of File Name?

Jun 7, 2014

I have 800+ files the problem is that the file name ends in 80 different combination so I need to try all of those for each file.

eg: one of the 800 is "109 st no 103 av" the file could be called:
"109 st no 103 av nb1_cleaned.xls" or
"109 st no 103 av nb 1_cleaned.xls" or
"109 st no 103 av nb 1._cleaned.xls" or
"109 st no 103 av sb1_cleaned.xls"
.
.
.
.etc

I wrote a code to try all those combinations, the issue lies a space the code adds before _cleaned, how to remove it?.

So the name should be
"109 st no 103 av nb1_cleaned.xls"
but my code is letting it be
109 st no 103 av nb1 _cleaned.xls

Where the variable Ord is the "1" after nb.

Find the code below:

[Code] ....

View 2 Replies View Related

Extract Part Of Any Workbook Into Another

Apr 10, 2007

I need to have a macro written which will allow me to extract information from any given workbook and copy them to my workbook. I'm thinking along the line of creating an input box upon opening the workbook, asking for the name of the workbook which contains the data. I would then use the data from the workbook and extract bits of information which I would copy to my current workbook.

However, I can't seem to figure out how to direct the answer of the input box to extract the information out of the target. And how would I refer to the workbook with the data in my code? I would need to refer to the data workbook as I need to extract information from it.

View 5 Replies View Related

Extract Last Part Of Workbook Name

Jun 10, 2008

Is there a way to extract a specific part of the workbook and save it as a value in VBA:

For example:

Workbook title is "Data Set 2007" How would you extract 2007?

View 5 Replies View Related

Reference Cell From Another Workbook With Part Of Location?

Feb 20, 2014

I have the following formula/array:

='fake folder location[2013-004.xlsx]MgmtRpt'!$A$4

Now this works perfectly fine, but I am wondering if it is possible to replace 2013-004 so that it reads the text from a cell on that sheet to complete the file name.

Example:

A
B

1
2013-004
='fake folder location[2013-004.xlsx]MgmtRpt'!$A$4

I want to replace the 2013-004 in B1 with text from A1. I have tried multiple methods but it just always assumes it is part of the file name or breaks the formula.

View 2 Replies View Related

How Do I Subsitute Part Of A Formula Linked To Another Workbook

Jul 26, 2007

I've run into a roadblock in excel 2003 in trying to create an accounting spreadsheet that will pull in information from several separate workbooks (invoice files) using formulas which substitute invoice Nos. (which coincide with the tab/worksheet names).

My obstacle has something to do with order of operation/calculation I presume... I've successfully used labels to bring in information from separate tabs on the same file by using the substitute function with generic formulas.... in this case exel processes the formula, likely because it calculates the linked information first in its order of calculation; then trys to substitute information into the result of a calculation already made....

I'm trying to find a way to tell excel to look at respective cells in the same file but on a different tabs/sheets...

For example; I've been trying to pull in the date an invoice was issued for client "X".

I plug in a formula in a remote cell of my accounting spreadsheet "Y" which basically says to bring in the value on file ["X"]; worksheet "tab"; cell $J$11 - where "tab is just a filler that I would like to use the substitute function to exchange with respective invoice Nos. (i.e. 049; 050; 051; etc.) My hope is that by adding these 3-digit sheet identifiers; all other information from respective cells (in file "X") will be pulled into my accounting sheet - file "Y" (i.e. invoice total; applicable pst; gst; expenses; etc.) I have written as many formulas as required for the different types of info sought after, the only variable being the 3-digit worksheet identifier. The problem has been that excel first processes the formula in the remote formula cell(in file "Y"); then applies the substitute function to info already brought in from File "X"; whether it is a date value; or a currency value. I can't figure how to have the substitute function change the formula... not the result of the original function...!

I've tried to format the source formula cell as text (therefore not calculating a result at that instant) however the substitute function inherits the format of the source formula cell.

View 11 Replies View Related

Open/close Workbook Depending On A Part Of String

Jul 26, 2007

I have create a menu with buttons that are attached to the different projects of vba. This menu will be put in the server of my department so all my colleagues can take profit of the macros. Is a menu in an excel file that only contains the vba projects, not the sheets where the macros are supposed to run. My problem start when you want to open the file. It will always be in the same disk "P:COAP", and then there are more subdirectories (year, month)... so the total path, for example, this month is:"P:COAP2007200706". But every month, it changes, logically.

The problem is that i need to open a file with the name "COAP-200706 Concentració Empresa Emissora" in this case... the only thing that changes is month, and year...
I want to close the booke i choose, to avoid errors, if the name of the workbook chosen is different to a part of this string. In this case, i'm trying to close the book if the name of the file or the book don't contains the string "Concentració Empresa Emissora", without saving changes, of course... because sometimes people have chosen badly the files and they've made a disaster. If the file chosen contains this string in the name i want to continue with all the code that is written after.

ChDrive "P:"
ChDir "P:COAP2007"
NouFitxer = Application. GetOpenFilename
If NouFitxer = "" Then Exit Sub
Workbooks.Open Filename:=NouFitxer
If ActiveWorkbook.Name <> "*" & "Concentració Empresa Emissora" & ".xls" Then
Msg = MsgBox("Error in the file opened. Look at the name of the file next time." _
& vbCrLf & "The program will close without finishing the process. Start again. Thanks", _
vbOKOnly + vbCritical, ("END OF PROCESS"))
ActiveWorkbook.Close Savechanges:=False
Exit Sub
End If

View 2 Replies View Related

Reference Part Workbook Name In Formula From Date In Cell

Feb 20, 2008

i want to return a value from a cell in another workbook where part of the the workbook name is determined by a date set on the current open sheet.

so on my open sheet i have a cell where the user can change the date and i want the below formula to then use the date to look at the relevant file.

any ideas would be appreciated. know how to do this in VBA but no clue with formulas.

what i am trying to do is concatenate part of a file name and a cell value which contans a date

=VLOOKUP(A4,[accountsummary17022008.xls]Sheet1!$A:$B,2,FALSE)

View 3 Replies View Related

Multiple Lookup: List Of Part Numbers Based On The Product Part Code

Feb 12, 2009

I'm creating a worksheet that gives a list of part numbers based on the product part code. In most cases I can use the following.

=LOOKUP(O6,{0,1,2,3,4},{"NONE (M25)","SMP-55-001","SMP-55-004","SMP-55-008","SMP-55-014"})

so this gives a part number depending on what number is placed in O6. What I need to do know is look at 2 different cells and for each combination of numbers give a different part number. so if A1 is 2 and B1 is 3 give a certain result.

View 3 Replies View Related

SUMProduct (182 Matches Part 1 Of Which 32 Match In Part 2)

Nov 18, 2008

Using the below formula. I know that I should get the result of 32 if I am dong this correctly (182 matches part 1 of which 32 match in part 2).

=SUMPRODUCT(--($A$1='7. PM BDE'! $J$3:$J$366))*(--('7. PM BDE'!$L$3:$L$366=1))

View 3 Replies View Related

Remove First Part Of String Of Text And Keep The Second Part?

Feb 12, 2014

Is there any way to remove the first part of a string of text in a cell and save the second part?

The first part of the text string is a team code that has a variable number of numbers, capital letters and sometimes spaces. The second part of the text string is a variable number of words in a team name that all start with a capital letter and have lower case letters. Every line has a different team code and team name.

The original spreadsheet also has a column with just team code. Is there a way of using this column to "subtract" the team code from the text string to just leave the team name?

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved