Question: Is it possible to create a macro to change the background color of a row, when the first 6 characters of a cell (within that row) is a certain value? For example, I'd like to change the background of a row to blue, if the UPC Code in column C starts with '007007'. Answer: Yes, this is possible. To change the background color of a row based on a cell value, we will need to create a macro and then create a button to call the macro. Download Excel spreadsheet (as demonstrated below) In the spreadsheet below, we've created a button that calls a macro to update the background color of each row. The macro is called "Update_Row_Colors". It will start at row 7 and test each value in column C. The macro will stop testing values when it encounters row 2000.
|
After we click on the button called "Update colors", the spreadsheet now looks like this:
|
As you can see, the UPC in rows 7 to 14 started with '007007' so the macro updated the background color to blue. If the UPC started with '030087', the background color was updated to light green...and so on. This macro can easily be modified to accommodate more UPC codes, by adding additional values in the case statement. You can view the macro by pressing Alt-F11. Macro Code:The macro code looks like this:
|
Visit our busy book shop, were you can find latest books for beginners as well as advanced excel users.
Spreadsheet 123 Spreadsheet Software Development
See Spreadsheets for:
a.Hotel Management b.Personal Budget
c.Corporate Finance d.Rating Calculation e.Real Estate and Mortgage
f.Web Calc