UsedRange in all worksheets Wb1 to find matching value in Wb2.

BRB1983

Board Regular
Joined
Aug 29, 2019
Messages
61
I'm trying to get workbook 1, all sheets used range, if cell value = a cell value in column a of sheets"Final" in Wb2. if so color cell indexcolor 6. the following cod runs but no color change.
Code:
Sub color_matching_between_workbooks()
    Dim sh As Worksheet
    'Dim wb1 As Workbook
    Dim wb2 As Workbook
    Set wb2 = Workbooks.Open("C:\Users\Desktop\17057 System Line List.xlsm")
    Dim finalrow As Integer
    Dim i As Integer
    finalrow = wb2.Sheets("Final").Range("A6000").End(xlUp).Row
    For i = 2 To finalrow
    
    
    For Each sh In ThisWorkbook.Worksheets
Dim cell As Range


For Each cell In sh.usedrange
If cell.Value = i Then
cell.Interior.ColorIndex = 4
End If


Next cell
Next sh
    
    Next i
End Sub
 
If the blank cells are the only problem, give this a try:
Code:
Sub color_matching_between_workbooks()
    Application.ScreenUpdating = False
    Dim sh As Worksheet, srcWS As Worksheet, wb1 As Workbook, wb2 As Workbook, rng As Range, fnd As Range
    Set wb1 = ThisWorkbook
    Set wb2 = Workbooks.Open("C:\Users\Desktop\17057 System Line List.xlsm")
    Set srcWS = Sheets("Final")
    For Each sh In wb1.Sheets
        sh.UsedRange.Cells.Interior.ColorIndex = xlNone
        For Each rng In sh.UsedRange
            If rng <> "" Then
                Set fnd = srcWS.Range("A:A").Find(rng, LookIn:=xlValues, lookat:=xlWhole)
                If Not fnd Is Nothing Then
                    rng.Interior.ColorIndex = 6
                End If
            End If
        Next rng
    Next sh
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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