logo elektroda
logo elektroda
X
logo elektroda

VBA EXCEL - Change cell background color if value starts with ....

zbyszekz660 20325 5
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 11738650
    zbyszekz660
    Level 9  
    Hello

    Please help me solve the problem using VBA (Excel 2007)
    I have a range in which some data is entered in some cells. I would like the macro to search for cells whose values begin with "HIGH"
    E.g
    FROM HIGH 500
    FROM HIGH 501
    FROM HIGH 502
    FROM HIGH 503
    The attached macro works for me but if in the IF loop I specify the exact value of the cell and not just part of the text

    
    Sub polaczone()
        For Each kom In Range("l4:l3000")
       If kom.Value = "Z WYS" Then
                kom.Interior.Color = RGB(255, 0, 0)
            End If
        Next kom
    End Sub
    


    I know how to do it using conditional formatting but the code is part of a more complex macro and I would like to implement it in VBA code

    Thank you in advance for your help
    Regards
    Zbyszek
  • ADVERTISEMENT
  • Helpful post
    #2 11739003
    marek003
    Level 40  
    Enter another condition:

    Code: text
    Log in, to see the code
  • ADVERTISEMENT
  • #3 11739105
    zbyszekz660
    Level 9  
    Cool! it works thanks for your help
    I have one more question

    The loop below searches a range of cells in column A and when it finds a specific value it changes the background color for the entire row.
    Is it possible to limit row selection to, for example, the first 15 cells of a given row


    Code: text
    Log in, to see the code


    I am slowly learning the VB language, but there is still a lot to learn ahead of me.
  • ADVERTISEMENT
  • #4 11739128
    yogi009
    Level 43  
    You can also do this with conditional formatting.
  • ADVERTISEMENT
  • Helpful post
    #5 11739133
    marek003
    Level 40  
    try this (I write without checking - but it should work)
    change the line of code "With..." on:

    Code: text
    Log in, to see the code
  • #6 11739175
    zbyszekz660
    Level 9  
    Theoretically, I can do it by conditional formatting, but as I wrote earlier, it is only part of a more complex macro. This macro is attached to the form under the CheckBox control, so for now conditional formatting is off

    Added after 53 [minutes]:

    Quote:
    try this (I write without checking - but it should work)
    change the "With..." line of code to:

    Visual Basic Code - [expand]
    ...
    With Range(Cells(Row cell,1),Cells(Row cell,15)).Interior
    ...


    It works great. thanks for the help.
ADVERTISEMENT