Hi All,
I know this is an issue that has been discussed many times, but i couldn't find any threads with the approach i'm looking at.
I've often used the indirect function within a vlookup as a dynamic means of referencing the location array i want to lookup on, and this works very well on open workbooks but unfortunately not on closed ones.
I am looking at using VBA to input a normal vlookup (i.e. no indirect function) within a defined range where the 'array' part of the vlookup sits in column A.
I am fairly clueless with VBA but have managed to adopt some code i found when googling that nearly does what i want...
This code inputs a vlookup in cells E2:P25 on a workbook defined within MyPath cell A2. This does work for the very first row of the formula (E2:P2), but my problem is I don't know how to get the location in cell A2 to roll down with the vlookup so that E3:P3 uses the array in cell A3 etc..
I hope this makes sense, i can let you know the full structure of my workbooks if that would help but i didn't want to overload everyone with info straight away. Thanks in advance for any help you can provide
Cheers
Chris
I know this is an issue that has been discussed many times, but i couldn't find any threads with the approach i'm looking at.
I've often used the indirect function within a vlookup as a dynamic means of referencing the location array i want to lookup on, and this works very well on open workbooks but unfortunately not on closed ones.
I am looking at using VBA to input a normal vlookup (i.e. no indirect function) within a defined range where the 'array' part of the vlookup sits in column A.
I am fairly clueless with VBA but have managed to adopt some code i found when googling that nearly does what i want...
Code:
Sub VBVlookup()
Dim MyPath As Variant
MyPath = Worksheets("Journal Consolidation").Range("A2").Text
Range(Cells(2, 5), Cells(25, 16)).Formula = "=iferror(VLOOKUP($C2," & MyPath & ",column()-2,false),0)"
End Sub
This code inputs a vlookup in cells E2:P25 on a workbook defined within MyPath cell A2. This does work for the very first row of the formula (E2:P2), but my problem is I don't know how to get the location in cell A2 to roll down with the vlookup so that E3:P3 uses the array in cell A3 etc..
I hope this makes sense, i can let you know the full structure of my workbooks if that would help but i didn't want to overload everyone with info straight away. Thanks in advance for any help you can provide
Cheers
Chris