Auto fill cell color for row

thewiseguy

Well-known Member
Joined
May 23, 2005
Messages
1,019
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am trying to auto-fill cell color based on whether the value in column A is odd or even. Odd values would make the entire row (A-O) have no fill, and even values would make the entire row (A-O) have grey fill.

Can anyone provide any guidance?

Much appreciated.



/M
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
You should be able to use Conditional Formatting for that.
- Select A2:O??
- Home ribbon tab -> Conditional Formatting -> New rule ... -> Use a formula to determine which cells to format -> Format values where this formula is true:- =AND(ISEVEN($A2),$A2<>"") -> Format... -> Fill tab -> Choose grey -> OK -> OK
 
Last edited:
Upvote 0
You should be able to use Conditional Formatting for that.
- Select A2:O??
- Home ribbon tab -> Conditional Formatting -> New rule ... -> Use a formula to determine which cells to format -> Format values where this formula is true:- =AND(ISEVEN($A2),$A2<>"") -> Format... -> Fill tab -> Choose grey -> OK -> OK

so this is working to some extent however it is not filling based on the value in column A being odd or even. so a row that is grey is filling both an odd and even row in column A.
 
Upvote 0
Are you sure you followed the instructions exactly? In particular, did you select from A2 to O?? with A2 being the active cell after the selection?

Here is my test sheet. Does this look how it should?

Excel Workbook
ABCDEFGHIJKLMNO
1
24
33
456
5
6abc
75
84
933
100
CF
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A21. / Formula is =AND(ISEVEN($A2),$A2<>"")Abc
 
Last edited:
Upvote 0
Try this:
This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  9/16/2018  8:27:36 AM  EDT
If Not Intersect(Target, Range("A:A")) Is Nothing Then
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
IsEven = Target.Value Mod 2
If IsEven = 0 Then Cells(Target.Row, 1).Resize(, 15).Interior.ColorIndex = 48
If IsEven = 1 Then Cells(Target.Row, 1).Resize(, 15).Interior.ColorIndex = -4142
End If
End Sub
 
Upvote 0
Are you sure you followed the instructions exactly? In particular, did you select from A2 to O?? with A2 being the active cell after the selection?

Here is my test sheet. Does this look how it should?

Excel Workbook
ABCDEFGHIJKLMNO
1
24
33
456
5
6abc
75
84
933
100
CF
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A21. / Formula is =AND(ISEVEN($A2),$A2<>"")Abc


got it. i wasn't starting at row to so had to make the adjustment. thank you again.
 
Upvote 0
Try this:
This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  9/16/2018  8:27:36 AM  EDT
If Not Intersect(Target, Range("A:A")) Is Nothing Then
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
IsEven = Target.Value Mod 2
If IsEven = 0 Then Cells(Target.Row, 1).Resize(, 15).Interior.ColorIndex = 48
If IsEven = 1 Then Cells(Target.Row, 1).Resize(, 15).Interior.ColorIndex = -4142
End If
End Sub

this worked as well - thanks for the edu!
 
Upvote 0
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub

Hello My Aswer Is This

I'm fairly new to VBA so I was wondering if I may impose on you for a moment to ask a question. I'm wondering what the command of 'CountLarge' does? (See post #7 ) I looked in the HELP files, and found 'Count' and also 'Large' but couldn't find anything that looked like 'CountLarge'. I understand that 'IF' statement is a way to break out of the subroutine, it's just that the 'CountLarge > 1' part has me confused.

If there is a link I could go to for more information, I'd appreciate it if you could let me know. THANK YOU for any help you may be able to offer.

TotallyConfused (a state I'm in most of the time) :)
 
Upvote 0
Well this is a sheet change event script.
So if the user changes a cell value we want something to happen.
But we only want one cell change to occur.

So if Range("A1").value changes do this.

But we do not want the script to activate if the user for example selected 1000 cells and tried to change them all at once we do not want the script to run. Like if the user tried to select 1000 cells and tried to clear them we would not want the script to run.

Hope that is clear.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top