VLookup to Future Sheets and Files - excel-formula

I have a file recording monthly sheets. I am trying to organize a VLOOKUP to sheets that do not yet exist.
Example code: =VLOOKUP($A$60,'C:/Users/JimW/Desktop//[MonthlySheets.xlsx]January18'!$A$2:$B$50,2,0)
However, the code generates an error. Any way to get around this?

Wrap your function in IFERROR() :
=IFERROR(VLOOKUP($A$60,'C:/Users/JimW/Desktop//[MonthlySheets.xlsx]January18'!$A$2:$B$50,2,0),0)
The last ",0" is what you want displayed if the vlookup fails - often I put text such as "file closed" - the text needs to be in quotes.

Related

"We Found A Problem With Some Content In Excel" formula's trouble

I know that error "We Found A Problem With Some Content In Excel" has been asked a lot of times, but I haven't found my root cause for this problem.
In my excel file this error appears after I switch formula
=IFERROR(XLOOKUP([#Column1];Sheet1[Column2];Sheet1[Column3]);0)
to following formula
=IFERROR(XLOOKUP([#Column1];Value(Sheet1[Column2]);Sheet1[Column3]);0)
Basically, I am just adding Value() function as values in Column2 often appear to be "Number stored as text".
Data is added to the template file (it contains mentioned formulas) using GemBox. The algorithm is I have template, run the app that adds data to the file, then I open file and everything is good.
But as I correct the formula adding Value() function it breaks down as I try to open the file in the last step.
The only thing that comes to my mind is that xlookup function accepts the array of data, so I can't use Value function by passing array into it. But still, if I change my formula manually, it works well

Merging the cells in excel and giving the hyperlink using Spreadsheet::WriteExcel

I am using Spreadsheet::WriteExcel. I want to merge two cells and give the hyperlink to the content inside merged cells.
I have tried like this.
$Log_Sheet->merge_range('D2:E2','Home',$MergedFormat);
$Log_Sheet->write_url('D2','internal:sheet1!A1');
This is working fine but when I try to open a file it shows a warning saying File error: data may have been lost. This occurs because D2 cell is being overwritten.
How can I merge cells and give hyperlink in one call?
I can't promise this works on Spreadsheet::WriteExcel, but it does on Excel::Writer::XLSX. I'd encourage you to try it on Spreadsheet::WriteExcel.
With merged ranges, once you declare a format, you need to continue using it for that range and never use it for non-merged ranges. So, if you take your code and add the tag and the format object:
$Log_Sheet->merge_range("D2:E2", 'Home', $MergedFormat);
$Log_Sheet->write_url('D2', 'internal:sheet1!A1', 'Click Me!', $MergedFormat);
It does appear to work... on Excel::Writer::XLSX. Sorry to keep referencing that.
Alternatively, per the previous post (File Error:data may have been lost while giving hyperlinks), you can also use the built-in Hyperlink function within Excel:
my $merged = $workbook->add_format();
$worksheet->merge_range("A10:A11",
qq{=hyperlink("#'Sheet3'!A1","Click Here!")},
$merged);

Referencing a linked file from INDEX() in Excel (Office 365)

I've got a collection of about 40 Excel worksheets. They store information about the number of hours that people have spent working on different projects, with dates across the top row from left to right and project names down the first column. Each member of the team has their own separate worksheet.
I'm making a new worksheet that will add up the number of hours each person has spent on a specific project.
I'm using this formula to add up all the numbers in a particular range of a linked file:
SUM(INDEX('S:\path\to\folder[Username_2017.xlsx]Daily'!G:JG,JOB_ROW,0))
JOB_ROW is the row containing the numbers I want to add up. Columns G:JG cover 1 Jan - 31 Dec. Username_2017.xlsx is different for each of the 40 people.
The problem is that the formula only works if I create it by hand. I can't find any way to use a dynamic reference to the filename, which gets very tedious with 40+ files to reference. I thought this might work:
SUM(INDEX(INDIRECT(C3),JOB_ROW,0))
...where C3, C4, C5 etc. would contain automatically-generated filenames and references. But it doesn't work. I get #REF!. And Excel doesn't prompt me to link the files -- which suggests to me that it will never work this way.
I've also found that even when the spreadsheet is working properly with the manually-entered formulae, if I save it and re-open it then Excel tries to be helpful by stripping out the formulas and replacing them with the text #REF!.
Is it possible to do what I'm trying to do? Or do I need to learn some VBA?
I should point out that I've largely avoided using Excel in my career so far -- so if there's a better way to achieve this then I'd love to hear it.
Thanks in advance for your help.
ian0411 gave the simple answer to this question in the comments above: the answer is "you can't do that".
If he wants to post that then I'll accept it as an answer -- but for the benefit of anyone else reading this question and looking for alternative options, here's what I tried and what worked:
VBA
I wrote some very simple VBA using GetObject() to open and read from each of the workbooks. It worked, but a) it was very slow, and b) it seemed to keep all the files open as long as Excel was running, which caused other problems. It also crashed a lot.
I gave up on VBA.
Automating the filename replacement
The next option I tried was to have a column of filenames in Excel, with a column next to it containing the formula that I wanted to run on each file. Instead of putting the linked filename in the formula, I put a unique placeholder ('XXXXX' or whatever).
Then I made a little macro that (for the currently selected row) did a search and replace across the row to change 'XXXXX' to the filename in column A. I had to run the macro 40 times to cover each file, but I only had to do that process once. When I add a new file to the list, I'll just add a new line, copy the formulas, and update the filename.
I've now got a spreadsheet which works perfectly when the linked files are closed, and which doesn't rely on VBA.
Perhaps if my VBA skills were better I could have written something less flaky -- but doing it all with INDEX() seems like the fastest, most elegant, and most reliable solution.

Error when entering table_array with spaces in the name Excel Formula

first my apologies for being a noob with regard to Excel Formulas - I did search and did not find an answer.
I have a spreadsheet that I am trying to modify. I got two spreadsheets from a client, who gave me a working copy and one that he had modified. There is a #REF error in the modified version. If I look at the working copy the formula looks like this.
=VLOOKUP($C$1,'Client Rates'!$A$2:J$228,5,FALSE)
As you can see it has quote marks in the table_array parameter because it does have a space in it. However I cannot enter it this way as it throws an error every time I try. Error is something like this - 'There is a problem with this formula. Not trying to type a formula? ... '
How can I enter the work sheet as a parameter with spaces in the name into the formula?
Did you try F2 to edit formula directly. Then highlight section of formula you wish to change then select the actual data you want evaluated by the formula?
Excel will create the correct string for the sheet and area reference for you.
The problem is you are trying to copy and paste directly from on workbook to another. Copying ctrl-c and pasting ctrl-v from one workbook to another may not have the desired effect. If you copy first to notepad or some other text editor and then paste from that text editor all works fine.

Wildcard reference to another workbook with INDIRECT Function

I want to make a reference to another workbook , let's say its name is "My workbook.xlsm" with the INDIRECT Function in Excel.
However "my workbook" file name could have any other string/characters before it or after it.
let's say I'm Trying to lookup "Lookup Value"
=VLOOKUP(""&"Lookup Value"&"",INDIRECT("'["&""&"my workbook"&""&".xlsm"&"]"&"("&A7&")"&"'!$A:$H"),8,FALSE)
I've tried the above formula and when i remove the wildcards before and after "my workbook" reference and write the name of the workbook exactly as it is , the formula works fine, but when i place the wildcards the formula gives a REF Error.
I'm definitely doing something wrong.
can anyone help please?
thanks in advance.
A workbook referenced with INDIRECT() must be open for the reference to work. Therefore, this approach is a non-starter from the go, unless you happen to have all files that might potentially meet the wildcard criteria open at the same time with your first workbook.
You may want to have a look at the free add-in called MOREFUNC.XLL, which has a function INDIRECT.EXT() that works with closed workbooks.
Edit: there are no wildcards in your formula above. A wildcard can be a ? for a single character or a * for any number of characters. The wildcard usage for INDIRECT with sheet names is explained in the video in your comment. For your example the formula would look like
=VLOOKUP(A2,INDIRECT("'[*my workbook*.xlsx]Sheet1'!$A:$H"),8,0)
There is no need to split up a string into a series of concatenated strings, but if you do, it does not make a difference.
You will find that this formula will always return an error, though. Indirect cannot parse wildcards in file names. It works fine with sheet names.
As I said in my comment: Since the file with the lookup table needs to be open anyway, so INDIRECT() can work in the first place, you can use a regular Vlookup with a direct reference to "my workbook". If you rename that file, the Vlookup formula will reflect the change immediately.

Resources