Consulting

Results 1 to 4 of 4

Thread: Solved: Change Cell Colors VBA

  1. #1

    Solved: Change Cell Colors VBA

    I need a script to check all cells from : "a2:a" & xrow and if the value in the cell is between 0 - 200 , then colour the cell green if between 201 - 300 amber , if between 301 - 400 then red , and if above 401 pink.

    Can anyone assist with the writing of this code ?? xld where are u ??

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

    Sub ProcessData()
    Dim LastRow As Long
    Dim i As Long

    With ActiveSheet

    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    For i = 2 To LastRow

    With .Cells(i, "A")

    If IsNumeric(.Value2) Then

    Select Case .Value2

    Case Is <= 200: .Interior.ColorIndex = 10
    Case Is <= 300: .Interior.ColorIndex = 45
    Case Is < 400: .Interior.ColorIndex = 3
    Case Else: .Interior.ColorIndex = 7
    End Select
    End If
    End With
    Next i
    End With
    End Sub
    [/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
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I was running behind but I'll post it anyway.
    [vba]Private Sub worksheet_change(ByVal target As Range)
    If target.Count > 1 Then Exit Sub
    If target.Column = 1 And target.Row <> 1 Then
    Select Case target.Value
    Case 1 To 200: target.Interior.ColorIndex = 4
    Case 201 To 300: target.Interior.ColorIndex = 45
    Case 301 To 400: target.Interior.ColorIndex = 3
    Case Is > 400: target.Interior.ColorIndex = 7
    Case Else: target.Interior.ColorIndex = xlAutomatic
    End Select
    End If
    End Sub[/vba]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    thanks guys, works a treat .. i used xld's code

Posting Permissions

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