What is wrong with this code?

sizemorem

Board Regular
Joined
Dec 12, 2008
Messages
103
I want to do conditional formatting on my spreadsheet. My labels are on row 7, columns A:E. I want my conditional formatting to start with row 8. It applies the formatting to row 8 but changes the formula to row 9. I don't understand.

Code:
Private Sub ConditionalFormattingForRefundCkReg()
    Selection.FormatConditions.Delete
 
    Range("A8").CurrentRegion.Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=IF(AND($E8=""Voided"",$D8>0),TRUE,FALSE)"
    Selection.FormatConditions(1).Interior.ColorIndex = 38
 
End Sub

The formatting that is cell A8 is:
"=IF(AND($E9="Voided",$D9>0),TRUE,FALSE)"

All help is GREATLY appreciated
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi

Code:
Range("A8").[COLOR=blue][B]CurrentRegion[/B][/COLOR].Select

You are selecting the current region and so the labels are also included, making row 8 the second row. That's why you get the 9 in the conditional formatting formula.

You should only select from row 8, down.
 
Upvote 0
If I use
Code:
Range("A8:E", Cells(Rows.Count, 1).End(xlUp).Row).Select

I get an error message about "Method or Object Failed"

Can you suggest another method of selecting an indeterminate range
 
Upvote 0
Works terrific now. It is amazing how just small items can mess everything up. I have a LOT to learn.

Thank you so much!!
 
Upvote 0

Forum statistics

Threads
1,218,627
Messages
6,143,584
Members
450,494
Latest member
GolfNut39

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