Table array in Vlookup not working when refering to a cell

Endered5

New Member
Joined
Oct 3, 2020
Messages
25
Office Version
  1. 2016
Hi,



I have some problem with VBA coding when i want to make a Vlookup and the TableArray always starts from Column "A" to "K", but the rows can differ depending on the situation.



For example

Range("P1").Value = Range("O2").Value & Range("M2").Value

Range("P2").Value = Range("O3").Value & Range("M3").Value



I have written "A" in cell "O2" and "K" in cell "O3". M2 and M3 is a row number I will get from a formula. So lets say M2=10 and M3=20, this means my "P1" will be A10 and "P2" will be K20. So the table array i want in Vlookup is A10:K20. But somehow the code is wrong, when i use "ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-8], Indirect(P1): Indirect(P2), 10, FALSE)"



I have tried many and different solution, but it didnt work out. This is my latest, but failed solution. I attach a file since maybe my explanation is not that good. It is supposed to do Vlookup under any column under "Last week" and to get the "current week" comments.



The whole code is here:

VBA Code:
ActiveCell.Offset(-2, -9).Select

ActiveCell.Copy

Range("M1").PasteSpecial

Range("M1") = Range("M1").Value

Range("M2") = "=Match(M1-4,A:A,0)"

Range("M3") = "=Match(M1-3,A:A,0)"

Range("M4") = "=Match(M1-0,A:A,0)"

Range("M4").Copy

Range("M10").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Range("M10") = Range("M10").Value

Range("M2") = Range("M2").Value

Range("M3") = Range("M3").Value

Range("P1").Value = Range("O2").Value & Range("M2").Value

Range("P2").Value = Range("O3").Value & Range("M3").Value

I = Range("M10").Value

Cells(I + 2, 10).Select

ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-8], Indirect(P1): Indirect(P2), 10, FALSE)"

End Sub
 
Last edited by a moderator:

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,276
Office Version
  1. 365
Platform
  1. Windows
If you are using FormulaR1C1 then all the references in the formula need to be in R1C1 notation.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,838
Office Version
  1. 365
Platform
  1. Windows
Cross posted Getting error while doing Vlookup for a TableArray that refers to a Variable

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered elsewhere.
 

Endered5

New Member
Joined
Oct 3, 2020
Messages
25
Office Version
  1. 2016

ADVERTISEMENT

Cross posted Getting error while doing Vlookup for a TableArray that refers to a Variable

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered elsewhere.

thanks for the information. Seems like i can not edit my original post?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,838
Office Version
  1. 365
Platform
  1. Windows
No need to edit it, as I have added the link for you this time.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,838
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Don't really understand what you are trying to do, but change O2 to B & then this should work
VBA Code:
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-8], Indirect(r1c16):Indirect(r2c16), 10, FALSE)"
 

Endered5

New Member
Joined
Oct 3, 2020
Messages
25
Office Version
  1. 2016
Don't really understand what you are trying to do, but change O2 to B & then this should work
VBA Code:
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-8], Indirect(r1c16):Indirect(r2c16), 10, FALSE)"

It is difficult to explain, but thank you so much! :) It works! Possible to put this thread as solved?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,838
Office Version
  1. 365
Platform
  1. Windows
Glad to help & thanks for the feedback.

We don't mark threads as solved here.
 

Watch MrExcel Video

Forum statistics

Threads
1,128,207
Messages
5,629,294
Members
416,384
Latest member
frsamiee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top