+ Reply to Thread
Results 1 to 4 of 4

Help needed in VBA code

Hybrid View

  1. #1
    Registered User
    Join Date
    07-31-2007
    Posts
    10

    Question Help needed in VBA code

    Hi Experts,

    I need to change the colour of the cells depending on the value in the cell.
    Condn 1: If value is "Start", colour of cell must change to "Red",
    Condn 2: If value is "In Progress" or "In Progress A" or "In Progress B" or "In Progress C" , colour of cell must be "Yellow" and
    Condn 3: if value is "End" or "Over", colour of cell must be "Green".


    If more words starting with "In Progress" would be added, how do i modify the macro which is given below?

    Private Sub Worksheet_Activate()
    Dim rng As Range
    Dim rCell As Range

    Set rng = Range("A1:A3000")

    For Each rCell In rng

    If rCell.Value = "start" Then
    rCell.Interior.Color = &HC080FF
    End If

    If rCell.Value = "in progress" Then
    rCell.Interior.Color = &H7AEAEF
    ElseIf rCell.Value = "in progress a" Then
    rCell.Interior.Color = &H7AEAEF
    ElseIf rCell.Value = "in progress b" Then
    rCell.Interior.Color = &H7AEAEF
    ElseIf rCell.Value = "in progress c" Then
    rCell.Interior.Color = &H7AEAEF
    End If

    If rCell.Value = "done" Then
    rCell.Interior.Color = &HE9FBA2
    ElseIf rCell.Value = "over" Then
    rCell.Interior.Color = &HE9FBA2
    ElseIf rCell.Value = "end" Then
    rCell.Interior.Color = &HE9FBA2
    End If
    Next
    End Sub

    Thanks in advance,
    Preethi.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Try


    Private Sub Worksheet_Activate()
    Dim rng As Range
    Dim rCell As Range
    
    Set rng = Range("A1:A3000")
    
    For Each rCell In rng
    
    If rCell.Value = "start" Then
    rCell.Interior.Color = &HC080FF
    End If
    
    'If rCell.Value = "in progress" Then
    'rCell.Interior.Color = &H7AEAEF
    'ElseIf rCell.Value = "in progress a" Then
    'rCell.Interior.Color = &H7AEAEF
    'ElseIf rCell.Value = "in progress b" Then
    'rCell.Interior.Color = &H7AEAEF
    'ElseIf rCell.Value = "in progress c" Then
    'rCell.Interior.Color = &H7AEAEF
    'End If
    If rCell.Value Like "in progress*" Then rCell.Interior.Color = &H7AEAEF
    
    If rCell.Value = "done" Then
    rCell.Interior.Color = &HE9FBA2
    ElseIf rCell.Value = "over" Then
    rCell.Interior.Color = &HE9FBA2
    ElseIf rCell.Value = "end" Then
    rCell.Interior.Color = &HE9FBA2
    End If
    Next
    End Sub
    rylo

  3. #3
    Registered User
    Join Date
    07-31-2007
    Posts
    10

    Question Vba

    Hi rylo,

    I tried using

    If rCell.Value Like "in progress*" Then
    rCell.Interior.Color = &H7AEAEF
    End If

    but, any word starting with "i" also gets converted to yellow colour.Its not working correctly.

    Thanks & Regards,
    Preethi.

  4. #4
    Registered User
    Join Date
    07-31-2007
    Posts
    10

    Thumbs up Thank you

    Hi Rylo,

    I tried it once again and it worked!!! Thanks a million!!!

    Warm Regards,
    Preethi.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1