Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

vba - Copy Format Conditions from one cell to another?

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...