VBA copy background color

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
This would do the copy and paste special method. But if you have conditional formatting, why not extend it to include column A based on the results in Column B

Sub Macro1()
'Try this out
Columns("B:B").Copy
Columns("A:A").Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range("A1").Select
Application.CutCopyMode = False
End Sub
 
Upvote 0
Hi, Trevor, thanks for you reply.
I have many sheets with this kind of things, and there will allways be changes. I think it will be easier to use VBA to do it before I close the file.
Do you have a way by useing vba to copy the background color?

Thanks
Frank
 
Upvote 0
Frank you apply what I have done into an Array.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Macro1()<br><SPAN style="color:#00007F">Dim</SPAN> ws <SPAN style="color:#00007F">As</SPAN> Worksheet<br><SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> ws <SPAN style="color:#00007F">In</SPAN> Sheets(Array("Sheet1", "Sheet2", "sheet3"))<br>ws.Activate<br>    Columns("B:B").Copy<br>    Columns("A:A").Select<br>    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=<SPAN style="color:#00007F">False</SPAN><br>    Range("A1").Select<br>    Application.CutCopyMode = False<br><SPAN style="color:#00007F">Next</SPAN> ws<br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
Hi, Trevor, this code will not copy the real background color, maybe you can have a test in the file which I gave here.
 
Upvote 0
Look at this website to see if it helps.

http://www.cpearson.com/excel/cformatting.htm

When I have used the code it works perfectly. I set Conditional formatting and applied a rule it works.

Excel Workbook
CD
1DataColoured
245
345
467
589
612
734
Sheet3

Conditions are:

=$C2<40 then red
=$C2>56 then green

Code used
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Macro2()<br><SPAN style="color:#007F00">'One sheet copy conditional formatting colour</SPAN><br>    Columns("C:C").Copy<br>    Columns("D:D").Select<br>    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=<SPAN style="color:#00007F">False</SPAN><br>    Range("A1").Select<br>    Application.CutCopyMode = False<br><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
I tried, Sorry, it does not work with my file, can you please have a test in my file, then you will know what I mean.

Thanks
Frank
 
Upvote 0
Frank I have copied your data, can you please show the Conditional Formatting Options you have applied. Or send a PM and give me an email address.
 
Upvote 0
Loop each cell in the intersection of usedrange and column A setting


For the cells with conditional formatting in column B:
cellColA.interior.color=cellColA.offset(,1).formatCondtions(1).interior.color

if there's no conditional formatting in column b then
cellColA.interior.color=cellColA.offset(,1).interior.color
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,280
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top