0

I am building a form to enter account information and order status. Each row needs to change based on the value of one of the cells on the same row, on this case cell "H". I can easily achieve this with conditional formatting but I think this makes the file bigger than programming code. I have tried some options but I can tell at this moment I'm way lost. I am attaching an example of what I want to accomplish. I don't know what to do at this point so if someone can help me I would really appreciate it.

enter image description here

1

1 Answer 1

2

A Worksheet_Change event macro¹ deals with, well, changes on the worksheet.

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Columns("H")) Is Nothing Then
        On Error GoTo bm_Safe_Exit
        Application.EnableEvents = False
        Dim trgt As Range
        For Each trgt In Intersect(Target, Columns("H"))
            Select Case LCase(trgt.Value2)
                Case "credit"
                    Cells(trgt.Row, "A").Resize(1, 12).Interior.ColorIndex = 45
                Case "completed"
                    Cells(trgt.Row, "A").Resize(1, 12).Interior.ColorIndex = 10
                Case Else
                    Cells(trgt.Row, "A").Resize(1, 12).Interior.Pattern = xlNone
            End Select
        Next trgt
    End If
bm_Safe_Exit:
    Application.EnableEvents = True
End Sub

H_credit_completed


¹ An event macro belongs on a Worksheet or Workbook code sheet; not a Module code sheet. For a worksheet code sheet, right click the worksheet's name tab and choose View Code. When the VBE opens, it will have the worksheet code sheet (typically titled something like Book1 - Sheet1 (Code)) in the foreground. Paste the code in and make any personalizing adjustments then tap Alt+Q to return to the worksheet.

3
  • Thank you for your reply, I think I may be doing something wrong because is not changing the color of the row. What I'm trying is to change the color range from "A" to "L" based on the value of "H" and it should apply for the entire workbook one row at a time
    – rogiefc
    Commented Jul 13, 2016 at 1:20
  • I've added an image and some basic instructions as to how to implement the code. More information is available by clicking the link that I provided in the original response.
    – user4039065
    Commented Jul 13, 2016 at 1:48
  • Now I get it, I have implemented the code and works like a charm. Thank you, I really appreciate your time to help me.
    – rogiefc
    Commented Jul 13, 2016 at 3:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.