Inserting VLookup With Variable Source Name With VBA?
Feb 23, 2012
I'm trying to create a macro that will open automatically generated report outputs and manipulate the data.
The macro will run from it's own workbook (Report Macro.xls), sheets / cells within this workbook are available as 'helpers'.
So far what I have working ok is;
Via a browse dialogs in a userform in Report Macro.xls I select 5 different report outputs. I'm storing the full filename & path in Sheet Data, Cells B1:B6 (B1 being the filename & path to the macro file). In column C I have just the filename
The first file is opened and manipulated as required. The next thing I need to do with it is to open the second file (filename / path in B3) and put a Vlookup in cell 02 of the first file which will look for data in the second (the second file will only ever have a single sheet).
As a formula I'd be using
Code:
=VLOOKUP(A2,'Email 22FEB12.XLS'!$B$7:$C$13120,2,FALSE)
In VBA if I use;
Code:
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-14],'Email 22FEB12.XLS'!R7C2:R13120C3,2,FALSE)"
It works great. However, the second filename will change and I need to take it from the macro file, sheet 'Data', cell 'C3'.
How can I use the contents of sheet Data, cell C3 in the VBA code above instead of the filename being hard-coded?
View 1 Replies
ADVERTISEMENT
Apr 19, 2006
I’m using these two codes to find a variable thru a source range. Everything looks to be working well, but as soon the macro tries to copy the returned range I got the following message. Run-time error ‘1004’: Copy method of Range class failed
However, when I press the end button in the error window, the returned range is copied into the target range. Does anybody know how to avoid the error message? Also, is there any way to pass the returned range to an array?
Note:
The source range is 40,000 rows by 14 columns
The returned range is 163 rows by 14 columns.
Sub SearchRangeOne()
Dim SourceRange As Range
Dim TargetRange As Range
Application. ScreenUpdating = False
Set SourceRange = Worksheets("Actual").Range("Actual_Key")
If Not Find_Range(Range("A1").Value, SourceRange, xlValues, xlPart) Is Nothing Then.............
View 8 Replies
View Related
Nov 23, 2012
I have a data set which is structured such that there are variable numbers of products (column A) from 1 - 48 and these repeat multiple times for each "Name" held in column B. I have attached an example of this which uses a data set with 7 entries reapeating 7 times.
I need excel to insert 2 formula for me multiple times which needs to varry according as follows
1. Calculate the average value of data in Column C - G for n cells starting at a specific cell (C2), I have inserted an example of this and highlighted it in yellow. This then needs to repeat down column C several times, the number of times this will repeat depends upon the number of different names held in column B. But I have this calculated already and stored in a cell im my main document.
2. Calculate the variance of each value in the x cells above from the average calculated in point 1 above. I have highlighted this also in yellow.
View 1 Replies
View Related
Dec 28, 2007
I am producing graphs that compare last years figures (static) with this years figures ( Dynamic) and this years figures come from a Pivot table and Worksheet that has been imported. The value returned in each cell for the graph's dataset is derived from a specific Pivot table row and the column name (month) that matches the column of the data set - so far so good. The formula currently looks like this.
=IF(ISNUMBER(GETPIVOTDATA("Duration of Spell",'Count PS'!$A$3,"Admission Hospital","Hillside","Discharge Date Month Name",Q3)),(GETPIVOTDATA("Duration of Spell",'Count PS'!$A$3,"Admission Hospital","Hillside","Discharge Date Month Name",Q3)),0)
where 'Count PS' is the name of the worksheet and Q3 is the reference cell that holds the Month Name. The problem is that I will not always be creating the report and other users may use a different name for the imported worksheet. I want to be able to set the name of the worksheet to be referenced in a supporting worksheet so that the user could simply amend the cell value to be the name of the source worksheet, but I can't work out the syntax
View 2 Replies
View Related
Nov 23, 2012
I'm analysing some data sets with variable content, and need to insert blank rows every so often to provide space to do some analysis. The problem I have is that the position of the blank rows change according to the data set, I have been able to calculate how often the row needs to be inserted using VBA as part of my import routine and saved this value to a cell, but I cant figure out how to write the VBA which will insert rows using this value and stop at the end of the data set.
In the attached example I need to insert a row each time the data in column 2 (name) changes, this is the value I have calculated which in this example is 7. So in this attached file I need to insert a row in row 2, row 9 and so on etc. But this is what changes depending upon the "Product" held in colum 1.
View 1 Replies
View Related
Nov 28, 2011
I have a workbook with 2 worksheets. 1 Worksheet contains a data table and another table contains a form
Worksheet 1 (Data)
[A] [B] [C]
1) [Material #] [Batch #] [Destruct Form #]
2) 10 100A 1A
3) 10 101A
4) 20 200A
5) 30 300A 2A
6) 30 301A
Worksheet 2 (Form)
[A] [B]
1) [Destruct Form #] [3A]
2)
3) [Material #] [Batch #]
4) [10] [101A]
5) [20] [200A]
I am looking to create a macro which, when executed, will:
1) search sheet 1 column B for any instances where a "batch #" from sheet 2 column B appears
2) add in the corresponding "Destruct Form #" from Sheet 2 Cell B1 into sheet 1 column b
Therefore after the Macro is run, sheet 1 will look like this:
Worksheet 1 (Data)
[A] [B] [C]
1) [Material #] [Batch #] [Destruct Form #]
2) 10 100A 1A
3) 10 101A 3A
4) 20 200A 3A
5) 30 300A 2A
6) 30 301A
View 9 Replies
View Related
Oct 8, 2012
I have a userform with a numerous textboxes, which I have labeled with similar text and a unique number at the end (num1_txt, num2_txt, num3_txt, etc.). I am trying to create a for loop that sequentially references the numbers of the text boxes and pulls the user-entered value in the text boxes into an Excel document.
Here is the code I have so far...
VB:
i = 1
For i = 1 To 18
Dim cyltrack As String
cyltrack = "Me.cyltrack" & i & "_txt.Text"
If Me.cyltrack.Value = "" Then
Cells((cellcount + i), 13).Value = "*"
Else
Cells((cellcount + i), 13).Value = cyltrack
End If
Next i
I am running into problems in trying to convert the string variable, cyltrack, into hard code that I could insert into Me.cyltrack.Value.
View 4 Replies
View Related
Sep 17, 2013
I current have a Vlookup looking at the source data in another workbook stored in a drive so that only limited people have access. Because this information is linked to a drive I thought that it wouldn't return a value if you didn't have access to the drive but I was wrong. Is there a way to remove the Vlookup information if you don't have access to the drive?
View 4 Replies
View Related
Jan 25, 2010
Inserting Variable Number Of Rows and Populating Data
View 10 Replies
View Related
Feb 12, 2010
I am having trouble with a number of workbooks when using vlookup (using the wizard rather than entering the formula directly)
First I select the cell with lookup value, then try to select the table array on the source sheet but the cursor changes to the hand symbol and I can't click on any cells. I have had this problem with many different workbooks. The only solution I have found is to copy the whole sheet, paste-special-values into a new sheet and use that as source.
View 11 Replies
View Related
Dec 17, 2013
I have 2 sheets, lets say SheetA1 and SheetA2. I am using Vlookup to serial number & getting data from SheetA1 to SheetA2. But I want to modifty the data. If i modify the data in SheetA2 that modification should relect in SheetA1. Is it possible...
View 5 Replies
View Related
May 21, 2009
I have around 700 workbooks in a folder on my PC.
My master file(master database.xlsx) is kept open from which i have to Vlookup the values into these 700 workbooks.
The "agent Id" column is common in both the master database.xlsx as well as those other workbooks also.
The thing i want to do is i need the data from the "reporting supervisor" which is in the master database.xlsx file to be available in the G column of the other 700 books ( i have attached only 4 sample books). The G column can be then named as "Reporting Supervisor". Since "Agent ID" is available in both files we can vlookup taking this as a base. I have attached the 4 sample files out of 700 as well as the master database file in a zip file.
View 14 Replies
View Related
Jun 6, 2013
I have an excel file - central database - that holds a lot of raw data organized in tables. There are more than 15 files (dependent files) that access this data using VLOOKUP formulas.
I now need to add a few columns to the central database and these columns can't be after the columns already existing, i.e. they have to be on the left of some of the existing columns. Inserting those columns is going to mess up all the vlookup formulas in the dependent files.
Is there a way change the central database file without affecting the vlookup formulas in the dependent files?
View 2 Replies
View Related
Jun 7, 2006
i have this super huge worksheet im working with and im trying to insert a vlookup forumla at the first blank cell at the end of each column. for some reason when i tried:
Range("B" & lastrowB + 1).FormulaR1C1 = "test"
it worked but.. when i tried
Range("B" & lastrowB + 1).FormulaR1C1 = "=VLOOKUP(A2435,[tmp.xls]vRptMOMarkToHedgeFacilities!$A:$BF,7,0)"
it didn't work. giving me an error on that line stating: Run-time error '1004': Application-defined or object-defined error.
View 6 Replies
View Related
Aug 26, 2009
I've used vlookup before but his #REF problem has me stumped.
I want to concat two cells in the Source worksheet and vlookup into the Defs sheet, but I keep getting #REF(G4:G6) when I want to return the 2nd column in the Defs sheet. What's curious is when I modify the vlookup to return the 1st column I correctly get the lookup cells(G6:G9).
What's wrong with the formula in G4.
My requirement is I can't change the format of the Source worksheet because it contains macros that work with ERwin. And it is MUCH bigger than the attached sample so I will copy/paste the formula down 6000+ cells.
View 2 Replies
View Related
Mar 28, 2013
I've got 3 columns of formulas that end up doing what I need, but I'm thinking it could probably be done easier with VBA.
I have 1 book with a sheet I'll call Log & another book with a sheet I'll call Source. On the Log, column E has the first 9 characters of vendor names & /vendor number (ex: EDMUND FI/00250), along with other data out through column P. On Source, the vendor names are in C & a short code for their name is in A.
I need to compare the first 9 characters in Log col E with the first 9 characters in Source col C. When a match is found, I need to return the short code from Source col A. BUT - if there's a duplicate in either Source col C or A, instead I need to return the word VERIFY, preferably with the cell highlighted in red.
Right now, I have, on Source col L:
Code:
=MID(C2,1,9)
and in source M:
Code:
=IF(OR(A2=A1,A2=A3,L2=L1,L2=L3),"VERIFY",A2)
This gives me the first 9 characters of the vendor name in L & the short code OR VERIFY in M
Then, in Log col R, I have an array formula:
Code:
=VLOOKUP(MID(E4,1,9),'[PRETICKET P ADDRESSES working.xls]Paddress'!$L:$M,2,FALSE)
This gives me either the short code or VERIFY from Source M. Also, sometimes it doesn't find a match & it returns #N/A. Then I have to do Conditional Formatting to make the VERIFY cells red & I thought I'd make the error cells be yellow (although I haven't figured out the CF for that yet)
Is there a better way to do this with VBA? I'm working with Excel 2010; just got it & still figuring it out.
View 2 Replies
View Related
Dec 29, 2009
I'm trying to do a vlookup inside of a FOR Loop where the lookup value is the name of a sheet, which I've made into a variable. When the next count of the FOR Loop changes, so does the sheet name. The formula gives me an error as the lookup value requires the sheet name to be in quotations in order for it to return a value. I've tried every possible combination without any success. Below, I've inserted the code
View 3 Replies
View Related
Jun 24, 2013
Trying to set a current region within a vlookup. Never done this before. Data in "test 1" sheet is somewhat dynamic: rows are variable; columns are set to 12 (A:L). Thought CurrentRegion would do the trick. And maybe it still could but referencing it into my vlookup errors out. is my syntax for the vlookup incorrect.
Set test_data = Sheets("test1").Range("A1").CurrentRegion
Sheets("Test2").Range("T2").Formula = "=VLOOKUP($F2,test_data,4,false)"
View 4 Replies
View Related
Apr 29, 2014
I am currently trying to use a variable instead of an absolute name for sheets name in VLOOKUP, but it wont work:
Original formula:
=VLOOKUP($D6,ABG!$B$9:$O$12,3,FALSE)
What I would like:
=VLOOKUP($D6,$A$6!$B$9:$O$12,3,FALSE)
with A6 = ABG
View 3 Replies
View Related
Jul 25, 2014
Basically have a spreadsheet to track an athletic competition going of for the purposes of a fantasy game (like fantasy football). The scores from each event are being copied and pasted into a data pages and then other pages pull from that for calculations. I'm using rankings (rank.eq equation) on a calculation tab, and then using those rankings on a leader-board tab find placement via the VLookup function. The issue I'm running into is ties, when two people are ranked the same. I've been playing with this:
=IF(ISERR(VLOOKUP($J17,Men!$A$1:$G$43,7,FALSE)),VLOOKUP($J17,Men!$A$1:$G$43,7,FALSE),
VLOOKUP($J16,INDIRECT("Men!A" & LOOKUP(J16,Men!A1:A43)+1):$G$43,7,FALSE))
Where it checks for an error in the Vlookup, if its not an error then it does the VLookup, if it is then if looks up the previous ranking and the VLookup array uses Lookup to find the position of the last rank, increments it by one and starts the new Vlookup there.
View 10 Replies
View Related
Apr 7, 2014
Adjust this piece of code:
[Code]....
The lookup is for 00.2014, but this is to fixed. Want to use the same code next year to. So I already defined the variable 'jaar' which the user can choose with a validation. (and next year they set it to 2015).
I thought this code would do it but no luck:
[Code] ....
So what would be the correct way? Been shifting with the " " but its only make more and more mess.
View 2 Replies
View Related
Mar 26, 2014
I'm working on a project where I need to populate a column with vlookups taken from different workbooks, I have for the most part got it working. However currently, everytime it populates a cell it prompts the user to select the sheet from the workbook as there are two. The sheet name is always the same so I tried to add it into the code so it would avoid having to repeatedly click okay while it populated the table.
This is the original code where it asks for the user to select the sheet every time.
[Code].....
This is what is produced when it is run and the user selects the worksheet each time (which works perfectly fine):
[Code] ...........
I tried to enter the Full Costs sheet name into the code like so:
[Code] ......
However this produces the following:
[Code] .....
The issue I have found is that the square brackets that are around the filename are generated automatically, they aren’t in the actual filename and I haven’t put them in, so I am struggling to work out how to add the sheet name in where it wont be included within the square brackets, as that is what's breaking the lookup.
View 3 Replies
View Related
May 13, 2009
Effectively I need to concatenate two columns in Sheet1, and then vlookup each concatenated value from Sheet1 in another concatenated column in Sheet2 and return the value from the next column
Now that is quite straight forward, but I am new to coding, and I was wondering if there was a way of doing it that doesn't involve having the concatenated values written to a column as a formula. Ideally what I would like it to do is put the concatenated value of Sheet1 together as a variable (I think thats what you call them) and then look up that variable in Sheet2 without Sheet2 creating a concatenated column too.
I'm of the understanding that this might be slower than writing the columns, but there is a reason for my madness.
Let me know what you think, or if i'm barking. Any suggested reading would also be handy, I don't like to bug you guys for the full code straight out.
View 10 Replies
View Related
Aug 13, 2012
I have a huge list of data where in column A there are customers names. Column B i can see products they are renting and column C-Z are uinits that they are renting on a given date. (lets say c is August 1st, D is August 2nd and so on). What I want is that if i a new tab in A1 enter a given date and A2 a given model, I want in A3 a formula which would provide me with Totals of that product on specified date by all customers.
Customer name
Product
Aug 1
Aug 2
Aug 3
A
Ice
2
6
4
[Code] .......
So lets say If I ente August 2 and as product Blow, I would like to know how many products of Blow are rented on that day. In this case 3 .......
View 3 Replies
View Related
Nov 16, 2007
I am trying to do a vlookup that currently looks as follows:
Range("C2").Formula = "=VLOOKUP(A2,SAP!A$2:AA$42,2,FALSE)"
However, the selection of the table_array (SAP!A$2:AA$42) is a set value. Instead I would like to select all the data that is on sheet SAP. The idea is that the data set will not always be A2:AA42, so I need to make this part variable.
Normally I would use
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
to select the entire data set.
View 9 Replies
View Related
May 8, 2008
I have an Excel File with 2 worksheets.
Sheet1 contains column A as "Product Number", Column B as "Product Family". Rows contain about 20,000 lines of data. A Range has been created to cover both columns, and named "ProdRange"
Sheet2 contains Column A (blank), Column B with "Product Number"
What I am trying to do is start at the top of Sheet 2 "Product Number" (B2 is first cell ref), and use this value to do a Vlookup on Sheet 1, to extract the "Product Family" code on the Offset 1 - and insert it back into Sheet 2 Column A.
I have this below :
For i = 2 To LastRow
Range("A" & i).Value = "=VLookup("B" & i, ProdRange, 2)"
Next i
BUT for some reason it doesn't like the [ "B" & i ] part of the equation.
View 9 Replies
View Related
Feb 25, 2005
I write quite a few macros that require a vlookup formula. The table array is often dynamic which means I must change my program. I am trying to find a way to create the formula to accomodate the growth of the table array. I can count the number of rows in the table by the counta function, but then when I try to use that variable in the formula it bombs.
View 7 Replies
View Related
May 23, 2007
Im have a vlookup which is specifying a table array from another tab on my workbook i.e. =VLOOKUP(J21,'Norwich CR'!$B:$AZ,6,FALSE)
I have another lookup which is feeding back the names of each worksheet (in this example its "Norwich CR". The range will be the same always $B:$AZ but i want the formula above to vary depending on whether my other look up feeds back "Norwich CR" or "Ipswich CR". how i can get =VLOOKUP(J21,'Ipswich CR'!$B:$AZ,6,FALSE) instead just by reading from another column of lookup data????
View 2 Replies
View Related
May 28, 2014
I just started venturing into VBA. I'm trying to pull the data from a different workbook that will have the previous month as the sheet's name. I can't get the dynamic part of the code.
[Code] .....
View 5 Replies
View Related
Jan 27, 2012
I need to lookup a value in one of 20 lookup tables. Each table has a range name that is stored in a cell. In the formula below, U79 contains the number I want to lookup and cell P79 has the variable range name. Both formulas give me an N/A error. When I enter the actual range name in the formula, it works. how to use a variable range name?
=INDIRECT(VLOOKUP(U79,P79,2,FALSE))
=VLOOKUP(U79,P79,2,FALSE)
View 3 Replies
View Related