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

alcwho

New member
Local time
Tomorrow, 06: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.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:08
Joined
May 7, 2009
Messages
19,245
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)
 

alcwho

New member
Local time
Tomorrow, 06:08
Joined
Sep 28, 2023
Messages
21
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.
 

cheekybuddha

AWF VIP
Local time
Today, 23:08
Joined
Jul 21, 2014
Messages
2,280
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!)
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:08
Joined
Sep 21, 2011
Messages
14,310
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!)
That appears to work for me? (y)
=IF(B21="","",VLOOKUP(B21,INDIRECT("Passengers!$D$"&O21 & ":$E$997"),2,FALSE))
 

Users who are viewing this thread

Top Bottom