Go To Cells That Dont Match From Table

TycExcel

New Member
Joined
Apr 18, 2022
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
  2. Web
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).

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
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,223,881
Messages
6,175,161
Members
452,615
Latest member
bogeys2birdies

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