Vlookup from a table, column located on a different workbook - excel

I am trying to do a Vlookup from a table that is located on a different workbook.
From a similar post in this forum I got a working formula
=VLOOKUP(E37,tblCosts[#All],COLUMN(tblCosts[Jun-17]),FALSE)
I need to reference the table. How do I append the workbook name in the formula?
Once I have this formula working, how would I write it in VBA, reading the table name and the column name from cell values?

Use this syntax (with the target workbook open):
= VLOOKUP( Lookup_value, 'Target_Workbook_Name'!Table_Name[#Data], Col_index_num, FALSE )
It has been tried before, but it would be very slow. However, since you are using VBA suggest working with the ListObject object, instead of trying to replicate the manner in which it is done manually.

Related

what does "#" refer to in Excel

I have an excel sheet that was provided to me to implement a business flow.
I see a formula in a column as below:
=[#[Inventory]]
I understand that this copies data from other column with heading 'Inventory'. But when I try to mimic this on a different sheet for a different column , I don't get any values. I'm I missing something here.
It's a function of structure reference.
# means ThisRow.
You could learn more from:
https://support.office.com/en-us/article/using-structured-references-with-excel-tables-f5ed2452-2337-4f71-bed3-c8ae6d2b276e
The =[#[Inventory]] works only on columns, which are part of Excel Tables, created either from the Ribbon, through Ctrl+T (or through vba):
This style of formula works with Excel listobject tables. The # symbol refers to the current row of the specified column. There's a good intro guide here

How to reference a cell as table range when using vlookup

I have vlookups to pull specific data from a workbook and paste into a new workbook in the desired layout. The layout of the first workbook never changes however the name will change when i want to run this on a different file.
My current formula is =VLOOKUP(A3,[Workbook1.xlsx]Sheet1!$B$3:$XFD$7,2,FALSE)
I would really like it to reference A1 instead of Workbook1 so I could then just update the file name in A1 every time I want to analyse a different file. I should mention the Sheet name won't ever change.
I know you have to use INDIRECT but im unsure how it works. I did try =VLOOKUP(A3,INDIRECT(A1),$B$3:$XFD$7,2,FALSE) but then i'd too many arguments and when i removed the $B$3:$XFD$7 i lost the range i was searching in.
Thanks!
With INDIRECT you must create the whole string that denotes the range reference:
=VLOOKUP(A3,INDIRECT("'[" & A1 & "]Sheet1'!$B$3:$XFD$7"),2,FALSE)
One more note, that INDIRECT requires that the workbook be open to function, or will return an error.

Excel CountA not correct when opening workbook

I have a .xlsm workbook used as a template (I am using Excel 2010) to create a workbook when users wish to download via a website.
A copy of the template is made when a download is attempted and values are written into a lookup tab in the copy (there are 2 columns: name and id) via .NET code. This part works great.
There is a second tab that uses a COUNTA formula to determine how many rows of data are populated in one of the columns.
My problem is that the COUNTA formula is showing a value of 0 instead of the correct value when the workbook is opened and macros have run. If I were to manually enter the field and refresh the value the value will be correct.
The formula is:
=COUNTA(LOOKUP!A2:A1000)
Why doesn't this work and what can be done to make it work?
Hello Here is a pretty fast way to count all of the Cells in A
Sub btnCount()
Range("A1", Range("A1").End(xlDown)).Select
MsgBox Selection.Count
End Sub

Referencing a workbook through a named range in Excel

I have 3 workbooks - Parent1.xlsx and Child.xlsx
Parent1.xlsx has data that will be referenced by Child.xlsx through vlookup.
The vlookup formula is
=VLOOKUP(1,[Parent1.xlsx]Sheet1!$A$1:$B$7,2,FALSE)
That works fine.
Now I have to make a copy of Parent1.xlsx to Parent2.xlsx.
In order for Child.xlsx to work I have to change the formula to
=VLOOKUP(1,[Parent2.xlsx]Sheet1!$A$1:$B$7,2,FALSE)
That is ok if its just for 1 cell, but I need to do it for many cells.
To fix this, I plan to used a named range for the file name. So in Sheet2 of Child.xlsx, I have a named range "parent" that has the name of the file - Parent2.xlsx.
I can't seem to get that to work.
If the value for the named range "parent" is
'[Parent2.xlsx]Sheet1'
then I'm trying to get
=VLOOKUP(1,parent!$A$1:$B$7,2,FALSE)
to work.
Is this even possible? Other than copy pasted everything and using VBA, is there another possibility?
Thanks
If you just need to change all the external references to the file Parent2, rather than Parent1, choose the Data tab, Edit Links and click Change Source.
Try:
"=VLOOKUP(1," & ActiveWorkbook.Names("parent").Value & "!$A$1:$B$7,2,FALSE)"
Edit: just realized this is the VBA solution. This won't work in a cell formula.

Copy excel (2007) sheet to new workbook without formulas referencing original workbook

I have a workbook with two sheets. The first is full of data and calculations, the second is mostly cells with references to the first sheet. The second sheet also concatenates strings, and references to cells in the sheet, to form SQL commands used elsewhere.
There is also a second workbook (soon to be more). It has a sheet identical to the first sheet of the other workbook, except with different data. The problem I'm having is that the new workbook needs a sheet similar to the second of the original workbook (sorry if this is sounding confusing). I would like to simply duplicate the sheet and its formulas, which I tried using the 'move or copy...' option. Unfortunately, the formulas in the cells reference the first sheet from the old workbook, like this: =[foobar.xlsx]data!A1. Way too much data to remove them by hand. I can't just redo the formulas because I had to remove a lot of specific lines from the second sheet, so dragging the formula would not match up correctly. I'm currently trying to hack this together with REPLACE but if anyone can offer help it would be greatly appreciated.
CLARIFICATION:
When I copy the sheet, a formula will appear as =[foobar.xlsx]data!A1. I want it to just be data!A1.
Thanks :)
I hope this answers your problem, but I am a little unclear on your need!!!
Highlight all cells in the worksheet.
Perform a replace to replace = with say '=
This stops the formulas "being formulas"
Copy the sheet.
Perform another replace on the new sheet to replace '= with =
This converts back to formulas, referring to cells in your new workbook.

Resources