Register now or log in to join your professional community.
Changing background colors in Excel VBA is easy. Use the Interior property to return an Interior object. Then use the ColorIndex property of the Interior object to set the background color of a cell.
Place three command buttons on your worksheet and add the following code lines:
1. The code line below sets the background color of cell A1 to light blue.
you can use the conditional formatting in Home ribbon and their multiple choices or you can do your own by chose New rule
You could also use VBA (ColorIndex with variable row number).
Use Conditional Formatting in Home ribbon.
the way your for loop works is that it is changing every cell. It can be optimized to color the row up to the last column at once.
through conditional formatting .
Conditional Formatting option under Home Menu offers Highlight Color Rule.
I'm trying to highlight a row that's assigned to "RowNum" I want to highlight Columns A through O. I've tried the things below, But receive syntax errors on each.
sh1.Cells(RowNum,15).Interior.Color = RGB(127,187,199) sh1.Range("A"& RowNum :"O"& RowNum).interior.color = rgb (127,187,199)In the past, I've used this to highlight a set range or individual cells.
sh1.Range("W1:X1").Interior.Color = RGB(252,213,180)
sh1.Range("A" & RowNum & ":" & "O" & RowNum)
I find creating a new rule easy from conditional formatting in the Home Pane. You can select a cell, give it values, names etc. Next to it formulate it by identifying ones you want to colour by saying =isodd or =iseven. Then highlight and go to conditional formatting -> New rule and choose your colour. It will indicate which (True or False) Need to be coloured. Try it.