Mataunited18
Mataunited18

Reputation: 628

Coloring Entire Row doesn't work with VBA

I am trying to color the whole rows based on values from the row, but nothing happens.

Column AA are filled with values from ColorIndex.

 Sub color()

  Dim color As Integer

  For Each cell In Sheets(1).Range("AA2:AA7000")

    If cell.Value = 6 Then
    ColorIndex = 6

        ElseIf cell.Value <> 6 Then ColorIndex = -4142

    End If

    cell.EntireRow.Interior.ColorIndex = color

nextcell:

  Next cell

End Sub

Does anyone know what I am doing wrong?

Upvotes: 0

Views: 75

Answers (1)

Storax
Storax

Reputation: 12167

My guess is that you would like to do something like that

Sub color()

    Dim color As Long
    Dim cell As Range

    For Each cell In Sheets(1).Range("AA2:AA7000")

        If Not IsEmpty(cell) Then

            If IsNumeric(cell.Value) Then

                If cell.Value = 6 Then
                    color = 6
                ElseIf cell.Value < 35 Then
                    color = -4142
                Else
                    color = cell.Value
                End If
                cell.EntireRow.Interior.ColorIndex = color

            End If
        End If

    Next cell

End Sub

Upvotes: 1

Related Questions