Repeat macro down a column till there's no input data?

qprfan99

New Member
Joined
Feb 23, 2016
Messages
9
The title probably isn't very well worded :)

I have a worksheet with a macro which formats a cell with the RGB values from the previous 3 cells.

So A1 will have the R value (0 - 255), B1 will have the G value (also 0 - 255) & C1 will have the B value (0 - 255)
I have a macro in D1 which will look up the 3 cells to the left &, if they contain valid numbers, will format that cell with the correct RGB colour.

This just works for 1 cell at a time.
I'd like it to repeat automatically until there is no more valid data in columns A, B or C.

Perhaps I should mention that the workshhet I am working on has about 135,000 rows so I need the macro to run 135,000 times (oe else I'm going to have to press CTRL Z 135,000 times which doesn't bear thinking about)

This is the macro

Sub Color()
Dim R As Integer, G As Integer, B As Integer
R = ActiveCell.Offset(0, -3).Value
G = ActiveCell.Offset(0, -2).Value
B = ActiveCell.Offset(0, -1).Value
ActiveCell.Interior.Color = RGB(R, G, B)
End Sub

I probably don't have to tell you that I'm very much a beginner at this.

Kind regards
Larry
 
No. Neither worked. The code appeared with the line "ActiveCell.Interior.Color = RGB(R, G, B)" highlighted in yellow.
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi

I did.

Again, the macro worked for about 65,000 rows. But when I tried to copy these back to the original workbook it wouldn't let me because of the limit on formats.

I should mention that every time I ran the macro, Excel locked up for a considerable time Sometimes forcing me to exit the program through Task Master.

But thanks again for trying
Larry
 
Upvote 0
the limit on amounts is for the workbook so you were never going to be able to transfer them into the same workbook as that workbook would have to do the formats in itself.

I am not surprised it locked up a few times it is being asked to do a lot of work very quickly loads of times.
 
Upvote 0

Forum statistics

Threads
1,215,443
Messages
6,124,890
Members
449,194
Latest member
JayEggleton

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