delete conditional format and add another

ss6857

New Member
Joined
Jan 17, 2011
Messages
27
Hello and thanks for your help,

Right now I have a data sheet that is updated from SQL so the number of rows change when it is updated. Also, Rows are automatically highlighted yellow if cell $O4 = 1 and Rows where $E4 <= $E$2 are automatically highlighted blue. And I am trying to delete the format where the rows are highlighted blue. But If I were to manual type in 1 in one of the cells in column O, I would like that row to highlight yellow and follow the previous condition. And I would like this is VBA. I know I can go into Conditional Formatting and change it that way. But I would like to run a macro to do this.

Here is what I have:
Sub Clear_Cond_Formatting()
Dim rng As Range
Dim a As Long
Select Case Selection.Cells.Count
Case 1
Set rng = Cells
Case Else
Set rng = Selection
End Select
On Error Resume Next
rng.FormatConditions.Delete
For a = 4 To Range("E65536").End(xlUp).Row
If Range("$o4") <> 1 Then
Rows(a).Interior.ColorIndex = 4
End If
Next a
On Error GoTo 0
MsgBox "complete"
End Sub


Right now it is highlighting the whole table. It seems like it isnt reading the value in row O.

Sorry if it is confusing.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,223,980
Messages
6,175,763
Members
452,668
Latest member
mrider123

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