Conditional Formatting after VBA has ran not working

Claire Jackson

Board Regular
Joined
Jun 30, 2020
Messages
76
Office Version
  1. 2016
Platform
  1. Windows
Hi, I have a very simple spreadsheet that filters and sorts via VBA but the conditional formatting isn't correct once it's been sorted so I'm thinking the best way to fix it is to use VBA to conditionally format the data after the other VBA codes have been ran. Basically the data is filtered on row 3 and the data is in the range A3:Y1500. I need it to format the row (A:Y) orange if the data in column M on each row is greater than zero. Can anyone help?

The code I'm using is as follows:

Private Sub Worksheet_Activate()

Sheet4.Range("A3:BA5000").AutoFilter Field:=2
Sheet4.Range("A3:BA5000").AutoFilter Field:=7

With Range("A3:BA5000")
.AutoFilter Field:=2, Criteria1:="*Middlesbrough*"
.AutoFilter Field:=7, Criteria1:="*Submit Costs*"
End With

With Range("A3:BA5000").CurrentRegion
.Sort .Range("J3"), xlAscending, Header:=xlYes
End With

End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi Claire,

I have macros that autofilter data all the time. The CF seem to work just fine after the filtering and sorting. Can you provide the formula you are using for the CF.
 
Upvote 0
Hi, the conditional format is based on another tab which populates the data from column BE on the data tab to column M

I've uploaded a pic of the formula.
 

Attachments

  • CF.jpg
    CF.jpg
    66.2 KB · Views: 8
Upvote 0
Well if you want the CF to work properly you should probably make the formula change to : =$M3>0

And the range should be: $A$3:$Y$1500

I think if you make these changes, then you wouldn't have to add any code to change the CF each time you autofilter or sort. The reason is that your rows on the other sheet are not identical to the rows on your current sheet.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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