Question

  Asked: May 16 2008   8:17 PM GMT
  Asked by: Tstychalski


coloring rows "if" true


Excel 2003, Conditional expressions, Microsoft Excel, Conditional formatting

I have a profit & loss spreadsheet that I use to input expected expenses and then log the invoices when they are paid and I always highlight the row when I input the invoice number and invoice amount. Is there a way I can use conditional formatting or a function to automatically color the row if there is anything in a the invoice amount cell to indicate that the invoice was paid?

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
+1
Click to Vote:
  •   1
  •  0



If you are using Excel you have the conditional format where you can define 3 rules to change the visual format of the data when the conditions are satisfied.
Example:
In the AMOUNT columns you define that :

    if cell value is greater than 0 it will be colored green
    if cell value is lower than 0 it will be colored red
    if cell value is equal to 0 it will be underlined and colored blue


Here is a file example.

I hope this helps.


The conditional formating can be found in the format (menu)->conditional formatting.


However since you've used the exact combination ("conditional format"), I'm assuming you're already are familiar with it and your question was actually - "How do I format an entire line according to a cells value?".

This would require you to add a short script. One way to open the built in vba environment is to right click on your sheets tab at the bottom and chose "view code". Then In the text area change "General" to "Worksheet" and chose Change in the other (that's the event on which you'd like the code to be activated).
Here's an example of the code you could add -

Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Range 'We first declare a variable
For Each i In Target 'Now for every field in the changed area
'- we check if it's Coulmn A (1) and if the new value is possitive,
'if it is we change the color of the _ENTIRE ROW_ to horrid yellow!=)
If (i.Column = 1 And i.Value > 0) Then Rows(i.Row).Interior.ColorIndex = 6
Next i
End Sub

If you're interested in exploring more complex visual changes, I'd recommend starting recording a macro, doing them, stopping it and going back to code view, only this time choosing modules in the tree and your macro name to see how these changes may be expressed in native vba language.
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Microsoft Windows, SQL Server and Development.

Looking for relevant Microsoft Windows Whitepapers? Visit the SearchWinIT.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register