How to append reference cell in VLookup for Table_Array (1 Viewer)

alcwho

New member
Local time
Today, 22:08
Joined
Sep 28, 2023
Messages
21
Hi,

I got a row number, say row 315, then i try to start vlookup from that row to the end. So my formula will look like:

=vlookup(A1,$B$315:$D$500,2,0)

however, row 315 is a dynamic cell depends on the result i generate in another cell, e.g. cell B1. Cell B1 contains the exact row number (e.g 315)

I tried to incorporate B1 to the vlookup formula like =vlookup(A1,"$B$"&B1&":$D$500",2,0) or tried to concat the 'table_array', but it still doesn't work.

Can anyone help me on this? or using other functions to get the same result?

Thanks in advance.
 
you can also try to create a Function in a Module:
Code:
Public Function fnCreateRange(ByVal startCol As String, ByVal startRow As Long, ByVal endCol As String, ByVal endRow As Long) As Range
    Set fnCreateRange = Range("$" & startCol & "$" & startRow & ":$" & endCol & "$" & endRow)
End Function

then you can call this function within VLookup:
Code:
=VLookup(A1, fnCreateRange("B", B1, "D", 500), 2, 0)
 
you can also try to create a Function in a Module:
Code:
Public Function fnCreateRange(ByVal startCol As String, ByVal startRow As Long, ByVal endCol As String, ByVal endRow As Long) As Range
    Set fnCreateRange = Range("$" & startCol & "$" & startRow & ":$" & endCol & "$" & endRow)
End Function

then you can call this function within VLookup:
Code:
=VLookup(A1, fnCreateRange("B", B1, "D", 500), 2, 0)
Thanks a lot :)

let me try.
 
I think you can also just use INDIRECT() without the need for VBA:
Code:
=VLOOKUP(A1,INDIRECT("$B$" & $B$1 & ":$D$500"),2,0)
(nb untested!)
 

Users who are viewing this thread

Back
Top Bottom