Consulting

Results 1 to 7 of 7

Thread: Solved: Colour change based on cell value

  1. #1

    Solved: Colour change based on cell value

        For Each a In Array("M", "P", "U", "X", "AC", "AF", "AK", "AN", "AS", "AV", "AZ")
        With ThisWorkbook.Sheets("Agent_View")
            For i = 18 To 47
                 With .Cells(i, a)
                    If IsNumeric(.Value2) Then
                        Select Case .Value2
                        Case Is <= 200: .Interior.ColorIndex = 43
                        Case Is <= 250: .Interior.ColorIndex = 44
                        Case Is >= 251: .Interior.ColorIndex = 3
                        End Select
                    Else
                        Cells(i, a).Interior.ColorIndex = 0
                    End If
                End With
            Next i
        End With
        Next a

    I have this code but it doesnt work the way I need it to , can anyone assit, if column az18 is
    <=200 then a18:h18 = .Interior.ColorIndex = 43
    <= 250 then a18:h18 = .Interior.ColorIndex = 44
    >= 251: then a18:h18 = .Interior.ColorIndex = 3

    then do the same with az19 all the way to az47

    can anyone help ?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    With ThisWorkbook.Sheets("Agent_View")
    For i = 18 To 47
    With .Cells(i, "AZ")
    If IsNumeric(.Value2) Then
    Select Case .Value2
    Case Is <= 200: .Cells(i, "A").Resize(, 8).Interior.ColorIndex = 43
    Case Is <= 250: .Cells(i, "A").Resize(, 8).Interior.ColorIndex = 44
    Case Is >= 251: .Cells(i, "A").Resize(, 8).Interior.ColorIndex = 3
    End Select
    Else
    Cells(i, "A").Resize(, 8).Interior.ColorIndex = xlColorIndexNone
    End If
    End With
    Next i
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    this doesnt work as it resize elswhere on the screen

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Maybe

    [vba]

    With ThisWorkbook.Sheets("Agent_View")
    For i = 18 To 47
    With .Cells(i, "AZ")
    If IsNumeric(.Value2) Then
    Select Case .Value2
    Case Is <= 200: .offset(), -51).Resize(, 8).Interior.ColorIndex = 43
    Case Is <= 250: .offset(), -51).Resize(, 8).Interior.ColorIndex = 44
    Case Is >= 251: .offset(), -51).Resize(, 8).Interior.ColorIndex = 3
    End Select
    Else
    Cells(i, "A").Resize(, 8).Interior.ColorIndex = xlColorIndexNone
    End If
    End With
    Next i
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    HI xld both codes dont work, the first code starts colouring from row az35 downwards , the second code just throws up errors

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Some extra brackets crept in there

    [vba]

    With ThisWorkbook.Sheets("Agent_View")
    For i = 18 To 47
    With .Cells(i, "AZ")
    If IsNumeric(.Value2) Then
    Select Case .Value2
    Case Is <= 200: .Offset(, -51).Resize(, 8).Interior.ColorIndex = 43
    Case Is <= 250: .Offset(, -51).Resize(, 8).Interior.ColorIndex = 44
    Case Is >= 251: .Offset(, -51).Resize(, 8).Interior.ColorIndex = 3
    End Select
    Else
    Cells(i, "A").Resize(, 8).Interior.ColorIndex = xlColorIndexNone
    End If
    End With
    Next i
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    thanks , worked

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •