Conditional Formatting a Table by row if negative values

TheRedCardinal

Active Member
Joined
Jul 11, 2019
Messages
250
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi all,

I have a requirement to add conditional formatting to a whole table, such that if the value in a specified column in negative, the whole row is highlighted.

I have come up against two blocks:

  1. My code doesn't actually work!
  2. I can't work out how to make it factor in that the relevant column might move

Here is the code I've used:

VBA Code:
Set FormRange = WS2.ListObjects(1).DataBodyRange

With FormRange.FormatConditions.Add(Type:=xlExpression, Formula1:="$I2<0")

    .Interior.Color = 65535
    .StopIfTrue = False

End With

It has populated the conditional formatting correctly:

1698154382927.png


But it doesn't take effect in the table itself.

Also, I have hard coded column I, but it might move - can I make the reference dynamic?

Thanks!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
i dont rovide VBA solutions here
BUT the formula
$12<0 has "" around it - so that will not work
needs to just be
$12<0
not sure how you apply that in VBA - been over 20years since i used vba in any big way

duplicate values is only looking in 1 cell
 
Upvote 0
Generally speaking, if you are searching (or wanting to search) for a value in a specified column that can move - a computer will have a hard time, unless there is something that is always (unique) in that column that will allow you to tell Excel to first find the column.

Might you be able to expand on that a little for us please ? (tricky for us right now as we can't see any of your data/table.)

thanks
Rob
 
Upvote 0
Your formula is missing an = sign: Formula1:="=$I2<0"
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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