Using VBA to match and highlight cells

angezprogolfcom

New Member
Joined
May 14, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi All Gurus,
I would like to use VBA to highlight matching cells.
Details:
Column 1 and 2 contain Name and Mobile of Customers.
Column 5 and 6 contain Name and Mobile of Customers who turned up for our Annual Sales.
I would like to match Column 6 against Column 2 and highlight Column 2 and 3 if the detailed match.
Please kindly advise solution.

Thanks a million.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
To add on: ( I am a beginner and my codes are definiely very simplistic)
I wrote the below but the results are quite erratic - sometimes it worked, sometimes it doesn't.

Sub AttendanceReport()

Dim x, z, iRowL As Long
Dim y As Integer

x = 5
z = 0
iRowL = Cells(Rows.Count, 2).End(xlUp).Row

Do While Not IsEmpty(Cells(x, 6))
y = Application.Match(Cells(x, 6).Value, Worksheets(1).Columns(3), 0)
If y > 0 Then z = z + 1
If y > 0 Then Range("B" & y & ":C" & y).Interior.Color = vbCyan
x = x + 1
Loop
Range("I5") = Range("A5:A" & iRowL).Count
Range("I8") = z
Range("A1").Select

End Sub
Please advise. Thanks
 
Upvote 0
Hi try
VBA Code:
Sub test()
Dim i&
Dim x
For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
x = Application.Match(Cells(i, 1), Range("e2:e" & Cells(Rows.Count, 5).End(xlUp).Row), 0)
If Not IsError(x) Then
Cells(x + 1, 4).Resize(, 2).Interior.Color = vbRed
End If
Next
End Sub
 
Upvote 0
Hi try
VBA Code:
Sub test()
Dim i&
Dim x
For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
x = Application.Match(Cells(i, 1), Range("e2:e" & Cells(Rows.Count, 5).End(xlUp).Row), 0)
If Not IsError(x) Then
Cells(x + 1, 4).Resize(, 2).Interior.Color = vbRed
End If
Next
End Sub
Thanks for your kind assistance. Tried - no result -
Hi try
VBA Code:
Sub test()
Dim i&
Dim x
For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
x = Application.Match(Cells(i, 1), Range("e2:e" & Cells(Rows.Count, 5).End(xlUp).Row), 0)
If Not IsError(x) Then
Cells(x + 1, 4).Resize(, 2).Interior.Color = vbRed
End If
Next
End Sub
Thanks again. I changed some parameters - It works great.
Thanks very much.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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