简体   繁体   中英

Pasting Cell Color with VBA using vlookup reference

I'm working on code for creating an org chart and want the ability to have the color of the source cell in a table to be pasted in the org chart. Currently the destination cell format is being driven from a pre-set format ("chartformat"). Code below. Any help would be much appreciated.

' Put Preformula

Range("preformula").Copy
Range("finalarea").PasteSpecial Paste:=xlPasteFormulas
Application.CutCopyMode = False
Sheets("Org Chart").Calculate

' Clear Blanks

Range("finalarea").SpecialCells(xlCellTypeFormulas, 4).ClearContents

' Put Format

Range("chartformat").Copy
Range("finalarea").SpecialCells(xlCellTypeFormulas, 2).PasteSpecial Paste:=xlPasteFormats


' Put Formula and Clear

Range("chartformula").Copy
Range("finalarea").PasteSpecial Paste:=xlPasteFormulas
Sheets("Org Chart").Calculate

Range("finalarea").Copy
Range("finalarea").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False

Have you tried pasting formats after pasting formulas?

Range("chartformula").Copy
Range("finalarea").PasteSpecial xlPasteFormulas
Range("finalarea").PasteSpecial xlPasteFormats
Sheets("Org Chart").Calculate

You should also qualify the Range with a sheet, especially since your macro is not limited to just one sheet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM