Copying Fill Colors using a Macro

mhp620

New Member
Joined
Jan 6, 2010
Messages
25
Could someone give some tips of copying just "fill" colors in a macro? I want to copy the fill colors in column 1 of a worksheet to all the columns across the worksheet.The rows have different fill colors.

Thanks in advance.

Mike
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Maybe like this

Code:
Sub Test2()
Dim LR As Long, LC As Long
Dim i As Long, j As Long
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
LC = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
For j = 2 To LC
    For i = 1 To LR
        Cells(i, j).Interior.ColorIndex = Cells(i, 1).ColorIndex
    Next i
Next j
End Sub
 
Upvote 0
Or faster(?)

Code:
Sub Test2()
Dim LR As Long, LC As Long
Dim i As Long
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
LC = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
For i = 1 To LR
    Range(Cells(i, 2), Cells(i, LC)).Interior.ColorIndex = Cells(i, 1).ColorIndex
Next i
End Sub
 
Upvote 0
Or faster(?)

Rich (BB code):
Sub Test2()
Dim LR As Long, LC As Long
Dim i As Long
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
LC = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
For i = 1 To LR
    Range(Cells(i, 2), Cells(i, LC)).Interior.ColorIndex = Cells(i, 1).Interior.ColorIndex
Next i
End Sub
Mike,

Peter accidentally left off the above indicated (in red) property reference.
 
Upvote 0
Rick

I have to thank you once again for correcting my slapdash coding.

Thanks again.
 
Upvote 0
I have to thank you once again for correcting my slapdash coding.

Thanks again.
You are welcome, of course, but you don't have to thank me for doing something like that... we all watch each others' backs here, right?;)
 
Upvote 0
Rick

I sometimes post air code (which I shouldn't) but you catch my errors. Greatly appreciated.


I note that you are an M$ MVP (well deserved) so I always value your contributions.
 
Upvote 0
I sometimes post air code (which I shouldn't) but you catch my errors. Greatly appreciated.
Again, you are quite welcome. As for "air code", I know what you mean. Almost everytime I decide the question is so easy that I don't need to check my code/formula solutions, it seems someone responds with a correction to what I posted.:eeek:

I note that you are an M$ MVP (well deserved) so I always value your contributions.
Thank you! October 1st is fast approaching so I will know in a couple of days or so if my Microsoft MVP status will be renewed (I'm not sure if my increasing contributions in this forum count when Microsoft considers such things or not).
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,917
Members
452,949
Latest member
beartooth91

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