INDIRECT function to specify external reference file - excel

I am using this formula to find the row number of the last valid entry in a sheet:
=SUMPRODUCT(MAX((ROW([A17U.SI.csv]A17U.SI!A:A))*([A17U.SI.csv]A17U.SI!A:A<>"")))
I have a list with several values, including "A17U.SI.csv" and "A17U.SI". Is it possible to reference those with the INDIRECT function?
Also, the reference A:A should not become a string (& A:A), it should remain dynamic so I can drag it to other columns.
Thanks for any input.

=SUMPRODUCT(MAX((ROW(INDIRECT("'[" & A3 & "]" & B3 & "'!" & SUBSTITUTE(ADDRESS(1,COLUMN(),4),"1","") & ":" & SUBSTITUTE(ADDRESS(1,COLUMN(),4),"1",""))))*(INDIRECT("'[" & A3 & "]" & B3 & "'!" & SUBSTITUTE(ADDRESS(1,COLUMN(),4),"1","") &":" & SUBSTITUTE(ADDRESS(1,COLUMN(),4),"1","") )<>"")))
Essentially, you are just needing to make your existing formula dynamic via the INDIRECT function. When using it, you just need to make sure you use the single quotes, brackets, and exclamation point to make the syntax valid. Your goal is simply to reproduce what you had hard-coded in there in your original formula.
The tricky part to your question was actually the need for a dynamic range reference, which makes the formula much uglier because we keep having to include this to get the letters for the range in a way that will be dynamically update:
SUBSTITUTE(ADDRESS(1,COLUMN(),4),"1","")
For example, if you put the above formula on its own in any cell in the A column, it will evaluate to "A". If you could put that in its own cell in the column, then you could simply reference that cell and it would make the formula a bit easier to read. For example, if we put =SUBSTITUTE(ADDRESS(1,COLUMN(),4),"1","") in cell A1, then we could write:
=SUMPRODUCT(MAX((ROW(INDIRECT("'[" & A3 & "]" & B3 & "'!" & A1 & ":" & A1)))*(INDIRECT("'[" & A3 & "]" & B3 & "'!" & A1 &":" & A1 )<>"")))
You asked about the syntax when using INDIRECT in SUMPRODUCT. By the time SUMPRODUCT is involved, if we wrote the INDIRECT part right, it shouldn't be any different syntax than what you already had.

Related

Excel data validation against a range with dynamic length on other sheet

I have data for drop down menus on a separate sheet called "DynamicListItems". The data is each on its own column. I can easily reference the data with =OFFSET(DynamicListItems!$D$3;0;0;COUNTA(DynamicListItems!$D:$D)-1;1)
But, I have hundreds of these drop down menus, and each need to be used on a different row. Is there a way to reference the range using the ROW() and COLUMN() or similar way so that I can copy the same formula into each data validation field?
Something like "=OFFSET(DynamicListItems!$" & COLUMN() & "$3;0;0;COUNTA(DynamicListItems!$" & COLUMN() & ":$" & COLUMN() & ")-1;1)" would be great, but Excel takes that as a one list option.
I found a solution. I use a named range with =INDIRECT("DynamicListItems!$" & COLUMN() & "$3:$" & COLUMN() & "$" & COUNTA(INDIRECT("DynamicListItems!$" & COLUMN() & ":$" & COLUMN())))

Is it possible to combine multiple cells into one while also omitting empty cells?

Is it possible to combine cells in one 'Outcome Cell' while simultaneously omitting any cell that is blank?
Below is an image of the desired outcome. Currently I'm having to use =CONCATENATE to get this outcome but then I have to go through it to remove all of the blank cells manually (with over 50 columns and 1000 rows this takes a long time).
Also is a link to the spreadsheet for you to see:
Excel spreadsheet
You can try this:
IF(NOT(ISEMPTY(A2)), A$1 & ": " & A2 & CHAR(10), "") & IF(…
EDIT:
=IF(NOT(ISBLANK(A2)), A$1 & ": " & A2 & CHAR(10), "") &
IF(NOT(ISBLANK(B2)), B$1 & ": " & B2 & CHAR(10), "") &
IF(NOT(ISBLANK(C2)), C$1 & ": " & C2 & CHAR(10), "") &
IF(NOT(ISBLANK(D2)), D$1 & ": " & D2, "")
All in one line. ISEMPTY is the VBA variant of the worksheet function ISBLANK.
Use the formula
=CONCATENATE(IF(A3="","","Size: "&A3&CHAR(10)),IF(B3="","","Material: "&B3&CHAR(10)),IF(C3="","","Colour: "&CHAR(10)),IF(D3="","","Weight: "&D3))
Note: make sure you have text wrap enabled on cells that contain line breaks.
This formula should help you:
=CONCATENATE(IF(NOT(ISBLANK(A2));CONCATENATE($A$1;":";" ";A2);"");CHAR(10);IF(NOT(ISBLANK(B2));CONCATENATE($B$1;":";" ";B2);"");CHAR(10);IF(NOT(ISBLANK(C2));CONCATENATE($C$1;":";" ";C2);"");CHAR(10);IF(NOT(ISBLANK(D2));CONCATENATE($D$1;":";" ";D2);""))
Take a look in my spreedsheet:
Excel
Use TEXTJOIN:
=TEXTJOIN(CHAR(10),TRUE,IF(A2:D2<>"",$A$1:$D$1&": "&A2:D2,""))
Depending on one's version this may need to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.

Is it possible to use Excel functions to evaluate the result of a function?

I have a formula in I2:
= "=" & "'" & $H2 & $I2 & E2 & "'!" & "$C$2"
It combines the directory, filename, sheet name, and cell location.
Now I'd like to evaluate the result of that formula in J2. Is it possible to do so without VBA or with just a bit of VBA? I need to be able to fill down I2 to I1000 and I personally prefer a non-VBA approach.
For example, let's say the result of I2 is:
='R:\20180220\[Test.xlsb]'!$C$2
Is there a way to actually show the value of that cell in J2? Note that workbook Test.xlsb is closed and won't be opened (because I have thousands of workbooks and cannot open all of them).
I tried EVALUATE(Range.Formula) and ExecuteExcel4Macro() in VBA, and tried to wrap them with a UDF, but both failed.
Here's a kludge that may work for you.
Create the formulas as in your current post. Note that the result in your post lacks a reference to a tab/worksheet --- you likely need to update your formula to include a worksheet. The formula I used in my tests is = "=" & "'" & $PATH & $FILE & $TAB & "'!" & "$C$2" (the same as yours but with a field added for the $TAB).
Copy/paste special values the results. This replaces = "=" & "'" & $PATH & $FILE & $TAB & "'!" & "$C$2" with ='C:\PATH\WORKBOOK\TAB!$C$2 to give the correct formulas. Annoyingly they do not calculate automatically.
To force an update of the calcs, F9 doesn't seem to work, so select the results and do a mock find/replace, say replace $C$2 with $C$2. This doesn't change the formulas but gets the recalc going. You might also be able to just save, close and re-open the workbook.
Hope this helps.

excel vba: insert formula with dynamic cell reference using vba?

I am inserting the following hyperlink as a formula using vba:
ActiveSheet.Range("AD" & ActiveCell.Row).Formula = "=HYPERLINK(""S:\Tasks\" & Range("C" & ActiveCell.Row).Value & "\log.txt"",""View Log"")"
This works fine, however if my value in cell C was to change then my hyperlink becomes invalid and won't work because it has retained the value of the cell at the time in which the formula was entered.
I need a way of making a dynamic reference to my cell C in the event that the value should change then my link will also change.
Can someone please show me how to do this? Thanks in advance
Your code is taking the value from column C and building a string using that value that looks like this:
"S:\Tasks\FolderName\log.txt"
Instead, what you want to do is build the following string:
"S:\Tasks\" & C2 & "\log.txt"
To do that, use this VBA code:
ActiveSheet.Range("AD" & ActiveCell.Row).Formula = "=HYPERLINK(""S:\Tasks\"" & C" & ActiveCell.Row() & " & ""\log.txt"",""View Log"")"

Excel 'Concatenate' with Alt+Enter, and then reference to another cell

This should be a simple process, but I am having difficulty producing the right outcome. I am trying to combine three cells into one, with Alt + Enter or Char(10) separating each value. When I use a simple Excel formula =B2 & Char(10) & C2 & Char(10) & D2 and wrap the text of the destination cell, everything seems normal. But if I try to search for a string in that cell (for example, "WS001"), it won't find the correct string. If I use VBA to perform the same function (i.e. ThisWorkbook.Worksheets("Sheet1").Cells(2, 1) = Cells(2, 2) & Chr(10) & Cells(2, 3) & Chr(10) & Cells(2, 4)), I can then search for the string in B2 and it fill find it.
That problem was addressed (to a degree), but then when I try to link the destination cell to a cell in a different Worksheet (=Sheet1!A2), I encounter the same issue where the search function can't find the string. Is there another method of doing this (I'd like to avoid VBA, because if someone has to edit the file/information in the future, they might not know how to change it)?
Can you clarify what you are looking for based on this example? Column A is the catenation of the three columns to the right, with CHAR(10).
Would you be for example searching for "Shane"? What result would you want?
EDIT
I'm having trouble understanding what you're looking for, but hopefully this can send you in the right direction.
This is my result:
B1 is the data to be searched for
The catenated formula is as follows: (This also worked when they were on a different sheet)
=C6 & CHAR(10) & D6 & CHAR(10) & E6
The "Catenated result" search formula is an array formula (ControlShiftEnter to enter formula)
="Row "&MATCH(TRUE,ISNUMBER(FIND($B$1,A6:A8)))
The "Individual result" search formula is also an array formula (ControlShiftEnter to enter formula)
="Column "&MAX(($B$1=C6:E8)*COLUMN(C6:E8))-2
(the minus 2 is because the first Source Value" column is column C (ie 3)

Resources