Vlookup with VBA

sahaider

New Member
Joined
May 30, 2014
Messages
35
Hello All,

I am trying to work with this vlookup in VBA but it's failing .

The range where the vlook up is looking for value of entries in column C is kept on a separate sheet called "Site ID to Cell ID" and in range A2 to B30287 . This worksheet is part of the same workbook.

the code is failing to return a value for the vlookup.

here is the code:


Code:
r=2
lastrow = Worksheets("NR_Best server by SS-RSRP").Cells.SpecialCells(xlCellTypeLastCell).Row

With Worksheets("NR_Best server by SS-RSRP")

For r1 = r To lastrow

.Cells(r1, 3) = Left(.Cells(r1, 2), Len(.Cells(r1, 2)) - 6)

.Cells(r1, 5) = Right(.Cells(r1, 2), 5)

.Cells(r1, 6) = .Cells(r1, 4) & "N" & .Cells(r1, 5)

.Cells(r1, 7) = .Cells(r1, 4) & .Cells(r1, 5)


.Range("D" & r1) = Application.WorksheetFunction.VLookup(Range("C" & r1), Worksheets("Site ID to Cell ID").Range("A2:B30287"), 2, False)

Next

End With

Thanks
Syed
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Looks like there is a dot missing in front of Range at this point
VBA Code:
VLookup(.Range("C" & r1)
 
Upvote 0
Are you getting a runtime error or an empty cell?

Either way, best guess would be no match found.
 
Upvote 0
As I said, most likely no match found. The problem appears to be the data, not the code.
If the problem is in the code, then it is not something that we will be able to find without the necessary data.
 
Upvote 0
Hello All,

I am trying to work with this vlookup in VBA but it's failing .

The range where the vlook up is looking for value of entries in column C is kept on a separate sheet called "Site ID to Cell ID" and in range A2 to B30287 . This worksheet is part of the same workbook.

the code is failing to return a value for the vlookup.

here is the code:


Code:
r=2
lastrow = Worksheets("NR_Best server by SS-RSRP").Cells.SpecialCells(xlCellTypeLastCell).Row

With Worksheets("NR_Best server by SS-RSRP")

For r1 = r To lastrow

.Cells(r1, 3) = Left(.Cells(r1, 2), Len(.Cells(r1, 2)) - 6)

.Cells(r1, 5) = Right(.Cells(r1, 2), 5)

.Cells(r1, 6) = .Cells(r1, 4) & "N" & .Cells(r1, 5)

.Cells(r1, 7) = .Cells(r1, 4) & .Cells(r1, 5)


.Range("D" & r1) = Application.WorksheetFunction.VLookup(Range("C" & r1), Worksheets("Site ID to Cell ID").Range("A2:B30287"), 2, False)

Next

End With

Thanks
Syed
Hello I checked your code with my data, and it works fine. Jason is right in case of your data no match is found. and i would suggest you to check the code by going step by step using debugger and see in the respective sheets , if you are getting what you want according to the steps.
 
Upvote 0
ok Pasted a snap of two worksheets. as you can see the data that is being looked into is available in the other sheet and not getting returned in the first sheet.
 

Attachments

  • NR_Best server by SS-RSRP.JPG
    NR_Best server by SS-RSRP.JPG
    45.4 KB · Views: 7
  • Site ID to Cell ID.JPG
    Site ID to Cell ID.JPG
    16.5 KB · Views: 7
Upvote 0
Cell format can't be correctly identified from those snaps, but if one is text format and the other is number then they will not match even though they are visually the same.

See if this works
VBA Code:
VLookup(CLng(.Range("C" & r1))
Based on the information so far, that shouldn't cause any runtime errors.
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,178
Members
449,071
Latest member
cdnMech

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