Excel vba vlookup error

roy123

New Member
Joined
Mar 8, 2018
Messages
3
please i need some help with this code below
Dim i As Integer Dim lrow As Long Dim x As Integer
Sheet4.Activate lrow = Sheet4.Range("A" & Rows.count).End(xlUp).Row
For i = 2 To lrow
Cells(i, 1).Activate x = Application.VLookup(ActiveCell.Offset(0, 0).Value, Worksheets(2).Range("A16:B25"), 2, False) If x <> Cells(i, 2).Value Then Cells(i, 2).Interior.Color = RGB(255, 0, 0) Else End If Next i
i have cells to look for in sheet4 and lookup table is in sheet2 range Range("A16:B25")
when i run this code it keeps saying mismatch error
please help
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try to declare X as a VARIANT ....
 
Upvote 0
Try this.
Code:
Dim i As Long
Dim lrow As Long
Dim x As Variant

    With sheet4
    
        lrow = .Range("A" & Rows.Count).End(xlUp).Row

        For i = 2 To lrow

            x = Application.VLookup(Cells(i, 1).Value, Worksheets(2).Range("A16:B25"), 2, False)
            If x <> .Cells(i, 2).Value Then
                .Cells(i, 2).Interior.Color = RGB(255, 0, 0)
            End If
        Next i
        
    End With
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,274
Members
452,628
Latest member
dd2

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