Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

How to change interior color in excel, across multiple columns using a row variable?

user-image
Question added by Imran Ahmed , Manager-Planning & Delay Analyst , Nesma United Industries (NUI) Saudi Arabia
Date Posted: 2016/08/16
Deleted user
by Deleted user

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.

Fatimh Ali
by Fatimh Ali , accounting , Ali Alkalifah

you can use the conditional formatting in Home ribbon and their multiple choices or you can do your own by chose New rule  

Tomasz L
by Tomasz L , Reporting Specialist , Outworking

You could also use VBA (ColorIndex with variable row number).

 

Abdrabou Sharafeldin
by Abdrabou Sharafeldin , Education Consultant , Educational Services

Use Conditional Formatting in Home ribbon.

Hussein Elkhouly
by Hussein Elkhouly , Sales Executive / Manager , VARIETY CRUISES

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.

Shady Ali - CMA
by Shady Ali - CMA , Senior Accountant , Smart Code for business services

through conditional formatting . 

Wasi Mohammad
by Wasi Mohammad , RF Drive Test Professional , Swedtel Arabia LTD

Conditional Formatting option under Home Menu offers Highlight Color Rule.

Ala'a Shalabiyeh
by Ala'a Shalabiyeh , Performance Information Management Assistant , Mercy Corps

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)

Bassam Ali Mohammed Al-mamari
by Bassam Ali Mohammed Al-mamari , مساعد الرصد والتقييم , برودجي سيستمز

sh1.Range("A" & RowNum & ":" & "O" & RowNum)

Deleted user
by Deleted user

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. 

using VBA or through conditional formatting

More Questions Like This