need to include if statement to a vba vlookup code

xl factor

New Member
Joined
Jun 1, 2011
Messages
2
Hello,

I have a piece of code that does a vlookup. I need to add an if statement to the same. cant seem to get it right.

The if statement is as below and the main code below it. Please help.

Code:
If Not varResult = "" Then
        rng.Value = varResult
End If
,



Code:
Sub vlookup()

Dim ws As Worksheet
Dim rng As Range
Dim varResult As Variant

Set ws = Worksheets("B1 Movements")
Set rng = ws.Range("M3")

Do
    varResult = Application.vlookup(rng.Offset(0, -10).Value, Worksheets("Movement Box").Range("C1:S100"), 17, False)
    If Not IsError(varResult) Then
        rng.Value = varResult
    End If
    Set rng = rng.Offset(1)
Loop Until rng.Offset(0, -10).Value = ""

End Sub

Thanks in advance.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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