I would like to be able to allow a user to change the file being used as a reference in a VLOOKUP. All the files being used will have the same array, just different files paths.
This is how i think it should operate.
Click macro button that opens file browser.
Allow user to choose file.
Paste file path in cell (A1)
Convert path to include array.
In VLOOKUP formula, reference the cell A1 as the 'table array'.
I am already able to complete up to step 3. Any idea on how to add the defined array and reference the cell in a VLOOKUP?
I would just record doing exactly what you want to do and then replace what you did with a variable that gets assigned, like when you place the path into cell A1. Then just have the macro re-write the appropriate vlookup formula.
You could also make a formula that would show what you want, and then use vba to copy that and paste values. You may then need to find and replace something in the cell(s) to get it to actually convert to a formula.
Example:
In A1 Put the path (with workbook name, i.e.C:\Users\username\Desktop\Book3.xlsx )
In B1 ="=VLOOKUP(D1,'"&MID(A5,1,FIND("*",SUBSTITUTE(A5,"\","*",LEN(A5)-LEN(SUBSTITUTE(A5,"\","")))))&"["&MID(A5,FIND("*",SUBSTITUTE(A5,"\","*",LEN(A5)-LEN(SUBSTITUTE(A5,"\",""))))+1,100)&"]Sheet1'!B$1:C$4,2,FALSE)"
B1 then looks like this =VLOOKUP(D1,'C:\Users\username\Desktop\[Book3.xlsx]Sheet1'!B$1:C$4,2,FALSE)
Copy B1 to C1 and do a find replace of something, like find Users and replace all with Users.
This is messy, but I use something like this for a tool that needs to update form 30 different files of different sizes based on 6000 rows of array formulas that update of yet another spreadsheet. It works well for me, but a bit slow for large files.
Related
I've got a list of 150 filenames in column A e.g. WorkBook1-WorkBook150 and want to reference this when including the file directory so I will be able to reference a cell out of the workbook. The cell is an outstanding amount for a particular supplier so I wish to create a workbook to have a full overview of the outstanding amount and broken down for each supplier in a list.
A1 filename: File1.xls
So if filename 1 is in A1, is there a way to action this so we can pull the filename from A1 and insert it in the relevant place in the directory? It works if I input the text from A1 manually but referencing the cell into the relevant place would save a lot of time.
Example of what I wish to input in B1: ='C:\Directory\FolderName[A1]Sheet1'!$D$4
Thank you for your time!
If I understand your question correctly, what you need is the 'CONCATENATE' formula. A1 contains 'filename.xls'. In B1 you can put: 'C:\Directory\FolderName\'
In C1 you can then put
=CONCATENATE(B1;A1)
which gives you
C:\Directory\FolderName\filename.xls
If you are trying to make it where you choose from a list you would need to use the data validation button and make a list. Make sure you have the reference in another cell.
Then you can use concatenate with the drop-down cell for efficiency.
I trying to make this formula flexible so I can search the value in a cell in multiple file paths and different excel files to give me a result.
My data in each excel fiel is in the same table for each workbook.
=VLOOKUP(A6,IndirectEx("'C:\_Excel\ExcelExamples\VLOOKUP_External_Sample\[Workbookname.xlsx]Master'!MatlDB"),1,0)
Can you guys help.
Thanks-
Based on your comment that the file paths are stored in a table, and assuming that these are on a sheet named "Locations":
=VLOOKUP(A6,INDIRECT(Locations!A1&Locations!B1),1,0)
This should work, but the cell references are hardcoded. Not sure how you want to select the references.
I answered my own question. So after some trial and error my result, and if someone can find a better way or help me create a macro, that would be awesome.
="vlookup(A1,"&"'"&""&A2&"\"&"["&A3&"]"&"SampleTab'!$G$62:$DU$175,A4,0)"
So what I had to do is write it as I was creating a text. Copied it into a different cell and remove the quotations from the formula.
Then move the range P114 , C117 , C122 & Q113
A1 would be the lookup value cell.
A2 would be the file path cell.
A3 would be the workbook name (note it has to include the file extension)
The range (SampleTab'!$G$62:$DU$175) has to be hard coded for now. A4 would be the row where the data is at.
I have a cell formula that's working mixing both text and an If statement, example: ="USER_INPUT" & IF(F2="Asia/Singapore","+08:00","+02:00") output: USER_INPUT+8:00
I'm not the one that will use this formula so I'd like to avoid having the user to search for the "USER_INPUT" in the whole formula in order to prevent mistakes.
Is it possible for the user just to type whatever he want in the cell wihout having the whole formula behind?
example of cell input I want:
="USER_INPUT" & formula
Is there any reason why the cell containing this formula cannot be in another location which the user does not need to edit? So I am suggesting that you have a highlighted cell somewhere for user input (say G2 for the sake of argument), and then in another cell you have the following formula:
=G2 & IF(F2="Asia/Singapore","+08:00","+02:00")
Your display cell can then refer to the cell containing the above formula. You could even take things a step further and lock the cells which contain the actual formulas, to make sure your users don't accidentally change them. Follow the link below for information on how to do that.
https://support.microsoft.com/en-sg/help/214081/xl-how-to-lock-individual-cells-in-a-worksheet
I have a cell number as a string ("A1") in a formula, and this needs to be changed relatively while copying, like it does automatically to normal cell references. so I don't have to visit 400 cells and change them all by hand.
Any way I can manage this? Thanks for the help.
Formula I am using in 400 cells:
=IF(IDENTIC($M$10;"Entries are correct.");IF(ISNUMBER(FIND("A1";$N$5));"S1";IF(ISNUMBER(FIND("A1";$N$6));"S2";IF(ISNUMBER(FIND("A1";$N$7));"S3";IF(ISNUMBER(FIND("A";$N$8));"S4";IF(ISNUMBER(FINDEN("A1";$N$9));"S5";"")))));"")
I don't want to change every single cell as text in all 400 cells, it should change relatively as normal cell references do.
To get a cell reference as a string in Excel you can use the CELL function:
=CELL("address";A1)
Since the second parameter to the function is an actual cell reference, if you copy and paste this formula it will auto-update accordingly.
Bear in mind this will return a string containing an absolute address so it will return "$A$1", not "A1".
CELL(...) will work.
More generally, you can also build the formula as strings using concatenations. This can be useful when you have a list of stuff and you would like to have formulas that refer to those names. Or in your case it would also work.
Building the formula as string with concats & then search & replace
First I build up as much as I can the formula so that the general structure is already formed (only the reference you'll want to change will not be final):
Using your case as an example:
Then, I wrap that nearly-formed formula into a CONCATENATE(). I then arrange things to have a references that I will point to within that CONCAT() that will auto-increment to the text I actually want to include in my formula. Something like this:
=CONCATENATE("IF(FIND(""",A1,"""$A$4),TRUE, FALSE)")
The ,A1, refers to the actual cell, so that cell's content is what will be included in my formula. You can then increment this all the way to build the proper formula for each cell (the 400 ones in your case). You need the triple """ because you want to actually include A1, B1 etc... are text references, not cells.
Then, all you need to do is selected all those formulas, copy them & make sure to choose past as values, say the line under (to keep you concatenate intact so you can edit it later if needed). Then with that pasted line all selected, you use a find & replace to add an "=" sign to the beginning of formulas. Better be too specific on the find & replace, so find "IF(F" and replace by "=IF(F" or similar. Then magic happens:
You can see that A1, C1, D1 have returned TRUE while the rest are #VALUE! because the find method has failed to find the string.
This seems like such an obvious thing that excel must have this feature, I just can't find it.
How can I create a custom function without using VBA? (VBA is too big of a hammer and causes security warnings, etc).
For example, I have a spreadsheet with several very complex formulas. Each of these formulas are replicated in several columns. Each column has hundreds of entries, so each one is replicated hundreds of times. If I tweak something then I have to manually fill-down or copy my change from one column to another.
A simple one looks like this:
=(Payment1 - F$12)*12 + ($D21-H21)
But what I'd like to do is:
=MyFunction(f$12,$D21,H21)
And have the actual formula for "MyFunction" written just once someplace.
I've found a few things that come close to giving me what I want. For example, in tables Excel will automatically replicate changes in a formula down the rest of the column saving you the step of manually selecting the range and doing a "Fill Down".
It will also allow relative references off of named cells, which seems equivalent of a user-defined parameter-less functions.
if you can use text to create the formula, then you can define a name to evaluate the function.
In cell A2, create a name EvalAbove, and in Refers To, enter =evaluate(A1)
This way, you can construct a formula
e.g. B1 contains SUM, B2 contains =("="&B1&"(A2:A5)")
and in B3, you can then put =EvalAbove
This means that if you change the formula name in B1, then B2 will change to show the changed formula, and B3 will change to show the result.
Note that this still counts as a macro enabled workbook, but there's no VBA code, just named ranges
You can do this for the example you show if I interpret it correctly.
If not you may be able to rearrange things slightly to conform
your function has three parameters:
The first comes from row 12 of the current column
The second from column D of the current row
The third comes from the column two to the right of the current row
I assume Payment1 is a named variable already?
Set the cursor in say F21 and then define this name
MyFunction =(Payment1 - F$12)*12 + ($D21-H21)
This will set the parameters to come from the places shown
To understand this better switch to RC mode and type the formula as:
=(Payment1 - R12C)*12 + (RC4-RC[+2])
You can now propagate down the formula through the F coloumn
=MyFunction
and it will always use the values in the corresponding F12 column Dxx and column Hxx
If you drag the formula to the next column it will use G12, Dxx and Ixx
If you want to change the formula edit it in the define name space
This is a general exception to the rule that you cannot have non-vba UDFs in Excel. Often in Excel the things you want as 'arguments' to the function are actually in fixed places (rows or columns) that can be addressed relatively.
For example you often want to perform a udf on the cell to the left
So a udf giving the cuberoot of the cell to the left would be a named formula like this:
Cuberoot =(RC[-1])^(1/3)
Or in a1 form set the cursor in B1 and type =(A1)^(1/3)
And Excel will convert it internally to the RC form
For three args - use three columns
It works and does not suffer the volatility issue mentioned about evaluate()
Yes I know this is an old posting but it may help someone with the same issue.
Bob J.