Hi Everyone,
I was trying to make a VBA code that would compare a list on a page "Locations", and go through all of the other sheets comparing a column in these sheets to see if there is a match or not. If there was no match, ignoring blanks, the VBA code would go to the cells where the match is not present so, the user can input a matching value from the list. For example, here is the location list.
"Rome"
"Paris"
"London"
"New York"
Then on other pages called "Trip Plan 1, 2, 3, 4, etc." in column A they have locations listed such as "Rome", "Los Angeles", "Sydney". I would want the sheet to go to that sheet and highlight the cells that contain "Los Angeles" and "Sydney" so, the user could change it from the list that contains "Rome", "Paris", etc. Here is the code I have so far, mostly from the Microsoft site WorksheetFunction.Match method (Excel).
I was trying to make a VBA code that would compare a list on a page "Locations", and go through all of the other sheets comparing a column in these sheets to see if there is a match or not. If there was no match, ignoring blanks, the VBA code would go to the cells where the match is not present so, the user can input a matching value from the list. For example, here is the location list.
"Rome"
"Paris"
"London"
"New York"
Then on other pages called "Trip Plan 1, 2, 3, 4, etc." in column A they have locations listed such as "Rome", "Los Angeles", "Sydney". I would want the sheet to go to that sheet and highlight the cells that contain "Los Angeles" and "Sydney" so, the user could change it from the list that contains "Rome", "Paris", etc. Here is the code I have so far, mostly from the Microsoft site WorksheetFunction.Match method (Excel).
VBA Code:
Sub HighlightMatches()
Application.ScreenUpdating = False
'Declare variables
Dim var As Variant, iSheet As Integer, iRow As Long, iRowL As Long, bln As Boolean, cel As Range, Test As String
Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet
Set ws = wb.Sheets("Locations")
'Set up the count as the number of filled rows in the first column of Sheet1.
iRowL = ws.Cells(Rows.Count, 1).End(xlUp).Row
'Cycle through all the cells in that column:
For iRow = 1 To iRowL
'For every cell that is not empty, search through the first column in each worksheet in the
'workbook for a value that matches that cell value.
If Not IsEmpty(Cells(iRow, 1)) Then
For iSheet = ActiveSheet.Index + 1 To Worksheets.Count
bln = False
var = Application.Match(Cells(iRow, 1).Value, Worksheets(iSheet).Columns(2), 0)
'If you find a matching value, indicate success by setting bln to true and exit the loop;
'otherwise, continue searching until you reach the end of the workbook.
If Not IsError(var) Then
bln = True
Exit For
End If
Next iSheet
End If
'If you don't find a matching value, don't bold the value in the original list;
'if you do find a value, bold it.
If bln = False Then
End If
Next iRow
Application.ScreenUpdating = True
End Sub