I have this excel formula which works perfectly to lookup a value in A1 from multiple sheets provided those sheets are on the same spreadsheet. I would like to extend it so it searches from an external spreadsheet where sheet_list is a list of sheet names on the external spreadsheet. Please help.
=LOOKUP(9.99999999999999E+307,1/COUNTIF(INDIRECT(" ' " &sheets_list&" '!A:A"),$A1),sheets_list)
I do exactly this :
IFERROR(INDIRECT("'" & $A$1 & $B$1 & $C$1 & "'!"&B$3 & ($A4+6) ),"file closed")
the cells a1, b1, c1 contain the path and file name detail, so all you need is to add your path / filename before the first ampersand in your expression.
Got it to work in this way:
=LOOKUP(9.99999999999999E+307,1/COUNTIF(INDIRECT("'[external_workbook_filename]" &sheet_names_array&"'!A:A"),$A1),sheet_names_array)
Related
I wrote code to put SUMIFs in a cell based on sheet name. newFileName and oldFileName are declared variables used as sheet names.
Sheets(newFileName).Select
Range("C2").Formula = WorksheetFunction.SumIfs(Sheets(oldFileName).Range("$G:$G"), Sheets(oldFileName).Range("F:F"), Range("B2"))
This works!
However, I want to put the SUMIFS formula in cell C2
Sheets(newFileName).Select
Range("C2").Formula = "=SumIfs(Sheets(oldFileName).Range("$G:G"), Sheets(oldFileName).Range("F:F"), Range("B2"))"
This gives a compile error. Any ideas how to make it work?
You need to write the formula in formula syntax, which means ' before and after the sheet name and ! before the ranges. More importantly, a formula is just a String so you should not be using Sheets or Range calls when constructing it:
Sheets(newFileName).Range("C2").Formula = "=SumIfs('" & oldFileName & "'!G:G,'" & oldFileName & "'!F:F,B2)"
Looking to get a range from another sheet based upon the Column Letter which is obtained from the current sheet.
So say that I designate A2 on the current sheet to the letter G.
I would then ask A10 to =AVERAGE('Sheet1'!(A2)2:(A2)999)
So essentially it would be =AVERAGE('Sheet1'!G2:G999)
However, this doesn't work. Anyone have any idea how to make this worK?
You would use the Indirect() function:
=AVERAGE(INDIRECT("'Sheet1'!" & A2 & "2:" & A2 & "999"))
If I have a cell, "a2" which has part of a filename/filepath, "sheet2.xlsx" in it which I want to use as a reference another workbook, how can I accomplish this?
I have tried using the INDIRECT function but always get a reference error.
I am trying to find a way to summarize a list of spreadsheets with column a containing the spreadsheet name and another column referencing a cell inside that respective sheet.
If the referenced workbook is open, then here is an example of getting a value from it:
=INDIRECT( "'" & A1 & "[" & B1 & "]" & C1 & "'!" & D1)
where the components are like:
Note we have specified:
the path
the filename
the worksheet name
the cell address
If the file is not open, you can still retrieve data with a ExecuteExcel4Macro (assuming you have a version of Excel that supports this function) For an example of this type of code, see:
Get Data from External Files
I have some dynamic input, in my case, the name of the month in cell I25. Based on the month the function in cell H32 should reference a sheet with the name of the month and cell A18 within that sheet. Now this I can handle and have made it possible through the INDIRECT function.
The issue I'm having is with dynamic range. For example, I would like cell H33 to reference cell A19 within the worksheet "February". The closest I got to it was =INDIRECT($I$25"&"!A18:A200"). And it seems to be working, but for some strange reason it starts referencing the cells contents from A36 onwards, which I don't get. Suggestions?
Any help would be greatly appreciated.
Use this one in H32 and drag it down:
=INDIRECT("'" & $I$25 & "'!" & CELL("address",A18))
Notes:
I've changed $I$25 & "!" to "'" & $I$25 & "'!" in formula to make it more reliable (for the case when sheet name contains spaces you should include your sheet name in single quotes like this: 'My sheet'!A18)
In H32 this formula evaluates to =Feb!A18 (where Feb is your sheet name), in H33 to =Feb!A19 and so on.
In excel 2007, I have a formula in a cell like the following:
=COUNTIFS('2008-10-31'!$C:$C;">="&'$A7)
Now I want to make the name of the sheet ('2008-10-31') be dependent on the value of some cell (say A1). Something like:
=COUNTIFS(A1!$C:$C;">="&'$A7) // error
Is there is way to do this? Or do I have to write a VBA-Macro for it?
INDIRECT does what you want. Note that if the sheet name has any spaces, you need to put single quotes round it, ie
=COUNTIFS(INDIRECT("'" & A1 & "'!$C:$C"); ">=" & $A7)
You are looking for the INDIRECT worksheet function:
=INDIRECT("SHEET2!A1")
=COUNTIFS(INDIRECT(A1 & "!$C:$C"); ">=" & $A7)
The function turns a string into a real cell reference.