I need to find a specific cell on a second workbook and return its value. I have a range that always changes, but I can filter out the bad values. The cell i need to copy (MCN #) from one workbook to another is changing in its format.
Sometimes it is single line, sometimes its merged over 7 or so lines.The code i have that works is:
=HLOOKUP("MCN #",[CuPe1810_CH520.xlsx]CuPe1820_CH520!$A$1:$S$16,2,FALSE)
I am looking for the "MCN #" off the linked workbook, and returning the line value (B3) that I assign to it on the primary workbook.
I need to have the [CuPe1810_CH520.xlsx] change from a user input value, and I need to have the tab or range (CuPe1820_CH520!$A$1:$S$16)change to the same name minus the .xlsx so in my example the CuPe1820_CH520 would repesent a tab name AND a .xlsx name. I need help in getting this to work based on user input and can be done formulas or macros, I do not care.
You can do something like this.
In the example below, F1
(or $F$1
for short code) is the cell that you are editing to update your formula.
A1
is the cell formula that we're updating.
If you have more than one cell you need to update, you can loop through them in a For Each
loop, or you can use the Range("SomeRange").AutoFill Destination:=Range("SomeDestination")
function.
Application.ActiveWorkbook.Path
may need to be updated in your situation - to point to the path of the file.
This goes in your worksheet object ( Worksheet_Change
event).
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$F$1" Then
'Range to update formula goes here
Range("A1").Formula = "='" & Application.ActiveWorkbook.Path & "\[" & [F1] & ".xlsx]" & [F1] & "'!A1"
End If
End Sub
In the above example, you don't need to put .xlsx
in the input string.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.