Excel VBA: Match Cell Color

后端 未结 3 1673
长情又很酷
长情又很酷 2021-01-23 07:10

I have a workbook with two sheets. On Sheet A, I have changed the interior color of some cells. I would like to find cells in Sheet B with matching text and set them to have the

3条回答
  •  情深已故
    2021-01-23 07:26

    This can be done much much faster with:

    Option Explicit
    
    Sub MatchHighlight()
    
    
    Dim FullListCell As Range
    Dim HighlightMasterCell As Range
    Dim FullList As Range
    Dim HighlightMaster As Range
    Dim lastRow As Range
    
    'find last row in FullList
    Set lastRow = Range("C").End(xlDown)
    
    Set HighlightMaster = ThisWorkbook.Sheets("kleuren_medewerkers").Range("A1:A100")
    
    Set FullList = Range(Range("C2"), ActiveSheet.Cells(lastRow.Row, 3)) 'change the number 3 to include more columns but use the lastrow of column C
    
    
    For Each HighlightMasterCell In HighlightMaster 
        For Each FullListCell In FullList 
            If FullListCell .Value = HighlightMasterCell.Value Then
                FullListCell.Interior.Color= HighlightMasterCell.Interior.Color
            End If
    
         Next
    Next
    
    End Sub
    

提交回复
热议问题