VBA Loop to fix Conditional Formatting ranges

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,632
Office Version
  1. 365
Platform
  1. Windows
I have a range that outputs a list that requires some cells t be merged dependent on how may rows of products are assigned to a customer

1731913593745.png


Above is a example of what needs to happen and in order to merged & word wrap the rows each customer needs for the products ordered I use the following
VBA Code:
Sub ROCFRanges()

Dim wsRO As Worksheet

Dim fcAll As FormatConditions

Dim fcSingle As Object

Set wsRO = ActiveSheet

Set fcAll = wsRO.Cells.FormatConditions

For Each fcSingle In fcAll
   fcSingle.ModifyAppliesToRange Range(Range("RO_CFArea").Address)
Next

Set fcSingle = Nothing
Set wsRO = Nothing

End Sub
Sometimes when the code to set the range for each of the CFs, Excel crashes.

This has happened where anything since the last save was lost and also it happened with the file being re-opened and repaired with no lost of data but essentially, this is an issue in case it happens when the process is deployed to my client.

Does anyone have a suggestion on a solution/work-around to avoid using this specific code?


TIA
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Maybe

VBA Code:
Sub jec()
 Dim j As Long
 With ActiveSheet.UsedRange.FormatConditions
   For j = .Count To 1 Step -1
     .Item(j).ModifyAppliesToRange Range("RO_CFArea")
   Next
 End With
End Sub
 
Upvote 0
Solution
I'll give it a go and let you know.
Maybe

VBA Code:
Sub jec()
 Dim j As Long
 With ActiveSheet.UsedRange.FormatConditions
   For j = .Count To 1 Step -1
     .Item(j).ModifyAppliesToRange Range("RO_CFArea")
   Next
 End With
End Sub

[/QUOTE]
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,208
Members
452,618
Latest member
Tam84

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