Consulting

Results 1 to 4 of 4

Thread: Solved: Change color figures, with discretion

  1. #1
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location

    Solved: Change color figures, with discretion

    Hi.
    I need help, in two parts of my code.
    When the cell 'A2' equals 'ret' form does not change color
    When the cells 'A2' is equal to or different from empty ("Los Tri, Los") all forms must be white.

    [VBA]Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Range("A2")) Is Nothing Then
    If Target.Value = "Ret" Then 'that part is not working
    ActiveSheet.Shapes("Ret").Select 'that part is not working
    ActiveSheet.Shapes("Ret").Fill.BackColor.RGB = vbYellow 'that part is not working

    ElseIf Target.Value = "Tri" Then
    ActiveSheet.Shapes("Tri").Select
    ActiveSheet.Shapes("Tri").Fill.ForeColor.RGB = vbRed

    ElseIf Target.Value = "Los" Then
    ActiveSheet.Shapes("Los").Select
    ActiveSheet.Shapes("Los").Fill.ForeColor.RGB = vbGreen
    Else
    ActiveSheet.Shapes("Los, Tri, Los").Fill.ForeColor.RGB = vbWhite 'that part is not working

    End If
    End If
    End Sub[/VBA]

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Got a sample workbook?
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    VBAX Mentor Teeroy's Avatar
    Joined
    Apr 2012
    Location
    Sydney, Australia
    Posts
    414
    Location
    The following works for me (in the sheet container of course). In this case I find a CASE SELECT more understandable code.

    ps: changed backcolor to forecolor for "Rec"

    [VBA]Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Range("A2")) Is Nothing Then
    Select Case Target.Value
    Case "Ret"
    ActiveSheet.Shapes("Ret").Fill.ForeColor.RGB = vbYellow

    Case "Tri"
    ActiveSheet.Shapes("Tri").Fill.ForeColor.RGB = vbRed

    Case "Los"
    ActiveSheet.Shapes("Los").Fill.ForeColor.RGB = vbGreen
    Case Else
    ActiveSheet.Shapes("Ret").Fill.ForeColor.RGB = vbWhite
    ActiveSheet.Shapes("Tri").Fill.ForeColor.RGB = vbWhite
    ActiveSheet.Shapes("Los").Fill.ForeColor.RGB = vbWhite
    End Select
    End If
    End Sub[/VBA]
    _________________________________________________________________________
    "In theory there is no difference between theory and practice. In practice there is." - Chuck Reid

    Any day you learn something new is a day not wasted.

  4. #4
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    that's right!!


    Very many thanks!!

Posting Permissions

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