help with a sub

J

Jock

Hi,
can anybody tell me why the following code fails at FormatConditions.Add

Private Sub CommandButton1_Click()

Dim Sh As Worksheet
Dim lngLastRow As Long

Set Sh = ActiveWorkbook.ActiveSheet
lngLastRow = Sh.Cells(Cells.Rows.Count, "A").End(xlUp).Row
Range("A4:E" & lngLastRow).Activate
Selection.FormatConditions.Add Type:=xlExpression,
Formula1:="=(MOD(ROW(),2)=0"
Selection.FormatConditions(1).Interior.ColorIndex = 24
End Sub

Thanks
 
G

Gord Dibben

See other replies for the error fix.

If you want the banding to stick when sorting or filtering use this formula.

=MOD(SUBTOTAL(3,$A1:$A$2),2)=0


Gord Dibben MS Excel MVP
 
J

Jock

Thanks for the heads up on the par.
Didn't sort it tho.
I still get "Object defined or Application defined error" at the same point.
I recorded a macro whilst applying banding and adapted it to search for the
last row which will change. I must be missing something obvious!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top