VLOOKUP error

rollingzep

Board Regular
Joined
Nov 18, 2013
Messages
214
Office Version
  1. 365
Platform
  1. Windows
I am trying to populate values on AK in ws TSS Trans, with S&P values from sheet, China by comparing AL with Ccode.

1668443600281.png

based on

1668443778873.png



This is my code, I am getting Subscript out of range error, at Chk line

<CODE>

LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
ws.Range("AK2:AK" & LastRow).Clear
With Sheets("TSS Trans").Cells(1).CurrentRegion.Resize(, 37)
Data = .Value
With Sheets("China").Cells(1).CurrentRegion
For i = 2 To UBound(Data)
Chk = Application.Match(Data(i, 38), .Columns(6), 0)
If Not IsError(Chk) Then Data(i, 37) = .Cells(Chk, 3)
Next i
End With
.Value = Data
End With
</CODE>
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Perhaps because you've set Data as a 37 column array and you're trying to reference column 38.
 
Upvote 0
Perhaps because you've set Data as a 37 column array and you're trying to reference column 38.
But I am trying to populate col 37 by matching the values of col 38 of the first ws to col 6 of the second ws.
Or maybe, I do not understand your reply.
 
Upvote 0
But I am trying to populate col 37 by matching the values of col 38 of the first ws to col 6 of the second ws.
Or maybe, I do not understand your reply.
I think I understand what you meant. How to declare the array the right way?
 
Upvote 0
In the third line, Change .Resize(, 37) to .Resize(, 38)
 
Upvote 0
Try using .Cells(Chk, 3).Value
I don't see any reason for the code to fail now but sometimes it can error if you don't use .Value.
 
Upvote 0
Try using .Cells(Chk, 3).Value
I don't see any reason for the code to fail now but sometimes it can error if you don't use .Value.
Not sure why it is not populating :(

I tried this
<CODE>
ws.Range("AK2:AK" & ws.Cells(Rows.Count, "A").End(xlUp).Row).FormulaR1C1 = "=VLOOKUP(""*""&RC[-38]&""*"",China!C1:C6,3,1)"
</CODE>

But I am getting #N/A. If I do, China!C1:C6,3,0. it populates the header, S&P. I need the values of S&P
What is the correct code?
 
Upvote 0
I'm not sure either, you've only posted part of your code so the problem could be elsewhere. Please post the full code. When you do please click on the </> icon and paste the code into the popup to post it. When you type the tags, you are not entering them correctly so the formatting is getting lost.
 
Upvote 0

Forum statistics

Threads
1,215,517
Messages
6,125,287
Members
449,218
Latest member
Excel Master

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
Back
Top