Sanoj
Sanoj

Reputation: 47

VBA code to copy conditional formating of one cell to unspecified range of cells

I am looking out for help with VBA code for conditional formatting. What I am looking for is copy formatting of my cell A1 to B2 till end of the row (that is B2:B till lastrow)

I tried the following but I know this will only format B2 cell. Can anyone help?

Sub FormatPainter()

Range("A1").Copy

Range("B2").PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False

End Sub

Upvotes: 0

Views: 3490

Answers (2)

Sanoj
Sanoj

Reputation: 47

Anyhow, I tried the following code and it worked.

Sub FormatPainter()
    Range("A1").Copy
    Range("B2:B" & Cells(Rows.Count, 2).End(xlUp).Row).PasteSpecial Paste:=xlPasteFormats
    Application.CutCopyMode = False
End Sub

Thanks for your time and support :)

Upvotes: 0

user3598756
user3598756

Reputation: 29421

Sub FormatPainter()
    Range("A1").Copy
    Range("B2", Cells(2, Columns.Count).End(xlToLeft)).PasteSpecial Paste:=xlPasteFormats
    Application.CutCopyMode = False
End Sub

Upvotes: 1

Related Questions