VBA control Condtonal formatting

Gvlewis81

Board Regular
Joined
Feb 5, 2013
Messages
202
Office Version
  1. 365
Platform
  1. Windows
Hi i've adapted the code below for a range of cells im tring to format.

Basically if the cell in column J's row is filled in fro A?:J? are to be filled.

I'm getting an error '1004' Method'Range' of object'_Global' Failed?

Any ideas ?


Code:
myrange = Range("A3:J" & Range("A2").End(xlDown).Row)
    
    
    With Range(myrange).FormatConditions.Add( _
        Type:=xlExpression, _
        Formula1:="=IF($J3<>"",TRUE,FALSE)")
        
    
        .Interior.Color = RGB(153, 204, 0)
       
    
    End With
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I still get the error on this part;
Code:
With myrange.FormatConditions.Add( _
        Type:=xlExpression, _
        Formula1:="=IF($J3<>"",TRUE,FALSE)")
 
Upvote 0
Guess I'm not following your request. You shouldn't need VBA for conditional formatting.

Are you trying to use the "Worksheet Change" event to color A thru J when J changes?
 
Upvote 0
Hi,

I'm creating a new sheet in the workbook and want to add the conditional formatting with VBA.
 
Upvote 0
I'm creating a new sheet in the workbook and want to add the conditional formatting with VBA.

Maybe this:

Code:
Public Sub Test()

Dim oFormat As Range

Set oFormat = ActiveSheet.Range("A3:J" & ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row)

oFormat.FormatConditions.Add Type:=xlExpression, Formula1:="=$J3<>"""""
oFormat.FormatConditions(1).Interior.Color = RGB(153, 204, 0)

End Sub
 
Upvote 0

Forum statistics

Threads
1,203,561
Messages
6,056,082
Members
444,844
Latest member
Taps07

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