Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to be able to write something like:

wks.Range("A1").FormatConditions = r.FormatConditions 

to copy conditional formatting from one cell to another. Is this possible to do? I want to copy conditional formatting from one cell to another by using one line of code, just like when I copy a formulas from one cell to another:

wks.Range("A1").Formula = r.Formula

Maybe there is a built-in command for this in VBA that I have not found? Maybe someone has written a custom sub for this?

r in the above examples is a range.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
259 views
Welcome To Ask or Share your Answers For Others

1 Answer

I don't think you can do it using one line of code. However, you can do it using two lines:

wks.Range("A1").Copy
r.PasteSpecial xlPasteFormats

This will copy all the formatting including the format conditions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...