Issue with VBA Vlookup with a Loop Function

Jdogg2022

New Member
Joined
Mar 21, 2022
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hi Guys,

Having an issue trying to get my VBA Vlookup to work as it keeps bringing up #NAME? in the box, and the VBA code is putting a @"E2"..
After every row, i'd like it to go down one step and increase the variable. Hence the need for my Integer. Screenshot below
1654679056335.png


export (4).xlsx
JKLMN
1Port Connect VesselPort Connect VoyagePort Connect ETAPort Connect ActivatedPort Connect Location
2#N/A#N/A#N/A#N/A#NAME?
3OOCL BUSAN522S22/06/2022 5:004/06/2022 10:19Vessel
4TORONTO TRADER125W13/06/2022 5:0030/05/2022 7:40Vessel
5TORONTO TRADER125W13/06/2022 5:0030/05/2022 7:41Vessel
ag-grid
Cell Formulas
RangeFormula
J2:J5J2=VLOOKUP($H2&$E2,Sheet1!$A:$BC,7,FALSE)
K2:K5K2=VLOOKUP($H2&$E2,Sheet1!$A:$BC,8,FALSE)
L2:L5L2=VLOOKUP($H2&$E2,Sheet1!$A:$BC,49,FALSE)
M2:M5M2=VLOOKUP($H2&$E2,Sheet1!$A:$BC,55,FALSE)
N2N2=VLOOKUP('E2',Sheet1!B:BC,5,FALSE)
N3:N5N3=VLOOKUP($H3&$E3,Sheet1!$A:$BC,9,FALSE)


Below is my loop

VBA Code:
Range("N2").Select
    
    For i2 = 2 To 1000
        
        'If Range("N" & i2).Value = "#N/A" Then
        If IsError(Range("N" & i2).Value) = True Then
            Range("N" & i2).Value = "=VLOOKUP(E" & i2 & ",Sheet1!C[-12]:C[41],5,FALSE)"
                                 
        End If
        
        If IsError(Range("N" & i2).Value) = False Then
            If Range("N" & i2).Value = "" Then
               Exit For
            End If
        End If
    Next i2
Any help would be appreciated! I've been racking my brains!

Cheers
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try it like
VBA Code:
            Range("N" & i2).Formula2R1C1 = "=VLOOKUP(r" & i2 & "c5,Sheet1!C[-12]:C[-8],5,FALSE)"
 
Upvote 0
Try it like
VBA Code:
            Range("N" & i2).Formula2R1C1 = "=VLOOKUP(r" & i2 & "c5,Sheet1!C[-12]:C[-8],5,FALSE)"
Hi Fluff,

Thanks for your response, its greatly appreciated. You are not far off the money! But now when I run the code it comes up with the below so the fomula doesnt calculate.. Got any other ideas how to solve? (its got the apostrophies around the E2)

Let me know your thoughts.

1654723741829.png
 
Upvote 0
Hi Fluff,

Thanks for your response, its greatly appreciated. You are not far off the money! But now when I run the code it comes up with the below so the fomula doesnt calculate.. Got any other ideas how to solve? (its got the apostrophies around the E2)

Let me know your thoughts.

View attachment 66631
HI Fluff,

I figured it out! It was the [ ] that was screwing everything up. Thanks for your kind support!

VBA Code:
For i2 = 2 To 2000
        If IsError(Range("N" & i2).Value) = True Then
            Range("N" & i2).Value = "=VLOOKUP(E" & i2 & ",Sheet1!B:F,4,FALSE)"
        End If
        
        If IsError(Range("N" & i2).Value) = False Then
            If Range("N" & i2).Value = "" Then
               Exit For
            End If
        End If
    Next i2
 
Upvote 0
Solution
You obviously did not use the suggestion I made as your image still shows you using columns B:BC which is pointless as you are only trying to get the value from the 5th column. ;)
 
Upvote 0
You obviously did not use the suggestion I made as your image still shows you using columns B:BC which is pointless as you are only trying to get the value from the 5th column. ;)
Yes you are correct, I change the lookup in the end.. But managed to get it working which was the main thing!
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,731
Messages
6,126,538
Members
449,316
Latest member
sravya

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