Highlight equal entries from separate worksheets

NewEE

New Member
Joined
Aug 10, 2021
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Hello All,

I receive a report on a regular basis with 17 columns and a variable number of rows. I want to highlight all of the equivalent entries in one worksheet (worksheet 1) with a single column of entries from another worksheet (worksheet 2), again with any number of rows.

Please see the code...

VBA Code:
Private Sub CommandButton2_Click()
'Highlight duplicates on both sheets

Dim ws As Worksheet
'The number of rows of data in the PO Generator File
Dim iRowsCount As Integer
iRowsCount = Worksheets(1).UsedRange.Rows.Count

'The number of columns of data in the PO Generator File
Dim iColumnsCount As Integer
iColumnsCount = Worksheets(1).UsedRange.Columns.Count


'The number of entries or tags to be checked
Dim tagCount As Integer
Worksheets(2).Activate
tagCount = Worksheets(2).cells(Rows.Count, 1).End(xlUp).Row

'The program seems to work until this point

Dim iRows As Integer
Dim iCols As Integer
Dim iTags As Integer

For iRows = 1 To iRowsCount
        For iCols = 1 To iColumnsCount
       
            For iTags = 1 To tagCount
           
                If Worksheets(1).cells(iRows, iCols).Value = Worksheets(2).cells(iTags).Value Then
                Worksheets(1).cells(iRows, iCols).Interior.ColorIndex = 26
                Worksheets(2).cells(iTags).Interior.ColorIndex = 28
                End If
           
            Next iTags
            '...need to cycle through every entry in sheet2, column A
           
        Next iCols
    Next iRows

For Each ws In Worksheets
    ws.Activate
   
    Debug.Print ws.Name
   
Next

Worksheets(1).Activate


End Sub

ExcelExPg1.PNG


ExcelExPg2.PNG
 
Last edited by a moderator:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Couple corrections needed:

VBA Code:
                If Worksheets(1).cells(iRows, iCols).Value = Worksheets(2).cells(iTags).Value Then
                Worksheets(1).cells(iRows, iCols).Interior.ColorIndex = 26
                Worksheets(2).cells(iTags).Interior.ColorIndex = 28

Where you have iTags in the first and third line ... it should be iTags, 1

You designated, the row (iTags), but you didn't designate which column.
The ' ,1' signifies the 1st column (Column A)
 
Upvote 0
Couple corrections needed:

VBA Code:
                If Worksheets(1).cells(iRows, iCols).Value = Worksheets(2).cells(iTags).Value Then
                Worksheets(1).cells(iRows, iCols).Interior.ColorIndex = 26
                Worksheets(2).cells(iTags).Interior.ColorIndex = 28

Where you have iTags in the first and third line ... it should be iTags, 1

You designated, the row (iTags), but you didn't designate which column.
The ' ,1' signifies the 1st column (Column A)
I'm afraid that that is incorrect. I also tried it, begrudgingly, knowing it wouldn't work. Cells() will take a single argument(parameter passed to it) as the row and it would assume the column is 1.
My problem seems to be that the macro won't escape the For loop and I don't know why.
 
Upvote 0

Forum statistics

Threads
1,214,830
Messages
6,121,839
Members
449,051
Latest member
excelquestion515

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