Autofill based on colour of cell

Lee241

New Member
Joined
Sep 30, 2011
Messages
2
Just started learning VBA last week, Where has this been all my life!

I've not even scratched the surface yet but have already automated loads of boring jobs which will save me lots of time and frustration in the future...

I've managed to sort most of my queries from searching through the answers in this forum but I'm completly confused with the autofill method and would like some help.

My task is simple, I select a range (always one column wide, number of rows could be anything even the entire column). I want to be able to autofill a formula one cell to the right of any cell in this range which is coloured green.

So far my code looks like

Sub Fillgreens()
Dim c As Range
Set c = Selection
For Each Cell In c
If Cell.Interior.Color = 5287936 Then Cell.AutoFill Destination:=Offset(0, 1)
Next Cell

End Sub

I'm still learning the basics of VBA (i.e I still have to stop and think whenever I read "properties, methods" etc to think what they actually mean) and would appreciate someone telling me why this is failing.

The error is "Autofill method of range class failed" and the selection of code highlighted is

Then Cell.AutoFill Destination:=Cell.Offset(0, 1)

Please don't laugh as I've tried and tested so many different things here that I have no idea what I've created trying to figure out exactly what is wrong!
 

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).
The destination has to include the starting cell so try

Code:
If cell.Interior.Color = 5287936 Then cell.AutoFill Destination:=cell.Resize(, 2)
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,159
Members
452,892
Latest member
yadavagiri

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