Forum Discussion

ronngrimes's avatar
ronngrimes
Copper Contributor
Jul 08, 2022
Solved

Auto fill color cells based on value of another color filled cell

I need help with an Excel macro that can analyze a numeric value within a cell that also contains a fill color (yellow) and it fill that same color into all cells having the same numeric value. I don...
  • OliverScheurich's avatar
    OliverScheurich
    Jul 08, 2022

    ronngrimes 

    The error message was because of the datatype Integer. For this code i used the datatype Long (in rows 3, 4 and 5 of the code) which can be used for much bigger values than Integer.

     

    Actually the standard fontcolor in Excel is 0 therefore i changed row 10 of the code. Fontcolor 3355443 was returned after pasting the data into Excel.

     

    In the attached file i've tested the code for range E100000:E110000 and it returns the expected result.

    Sub fontcolor()
    
    Dim i As Long
    Dim j As Long
    Dim MaxRow As Long
    
    MaxRow = Cells(Rows.Count, 5).End(xlUp).Row
    
    For i = 100000 To MaxRow
    If Cells(i, 5).Font.Color <> 0 Then
    
    For j = 100000 To MaxRow
    
    If Cells(j, 5).Value = Cells(i, 5).Value Then
    Cells(j, 5).Font.Color = Cells(i, 5).Font.Color
    
    Else
    
    End If
    
    Next j
    
    Else
    
    End If
    Next i
    
    End Sub

     

Resources