Conditional Formatting VBA Code

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,601
Office Version
  1. 2021
Platform
  1. Windows
I have data in columns A:J from row 12 onwards. I have written code to format the data in Col A:J if the value in col J is >=30 and three rows after the row in col J containing a value >=30.

When running the macro, it comes up wirth run time error 5 "Invalid procedure cal or argument and the following code is highlighted

.FormatConditions.Add Type:=xlExpression, Formula1:="=$J12>=30)"

Sub conditional_formating()
Finalrow = Range("a12").End(xlDown).Row
With Range("A12:J" & Finalrow)
.Select
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=$J12>=30)"
.FormatConditions(1).Interior.PatternColorIndex = xlAutomatic
.FormatConditions(1).Resize(3).Interior.ColorIndex = 15
End With
End Sub


It would be appreciated if someone could assist
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try

Code:
.FormatConditions.Add Type:=xlExpression, Formula1:="=$J12>=30"
 
Upvote 0
Hi Peter

Thanks for the help. did not see )

After correcting this error, I run the macro again and the following code is also not correct

.FormatConditions(1).Resize(3).Interior.ColorIndex = 15

If col J >= 30, I want to extend the color that was formatted by another 3 rows

Your assistance in this regard is most appreciated
 
Upvote 0
Maybe like this

Code:
.Resize(3).FormatConditions(1).Interior.ColorIndex = 15
 
Upvote 0
Hi peter

Thanks for the help, much appreciated
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,947
Latest member
Gerry_F

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