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
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
this should work

Code:
Sub Color()
Dim R As Integer, G As Integer, B As Integer
Dim i As Long
Dim LastRow As Long


LastRow = Cells(Rows.Count, 1).End(xlUp).Row


For i = 1 To LastRow


    Cells(i, 4).Select


    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)
    
Next i
End Sub
 
Last edited:
Upvote 0
It got to row 65,372 then locked up.

On debugging it showed this error message

Run-time error '1004':
Too many different cell-formats.

I tried to check this on the worksheet but just got an Excel dialog box saying "Too many different cell formats"

Larry
 
Upvote 0
In a standard excel sheet 2007 onwards you may have 64000 cell formats to get more you need to something with he registry which is beyond my skill set.
 
Upvote 0
Ok thanks for your help.

I'll see if I can copy the rest into another workbook/sheet & do the other 70,000

Thx again
Larry
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,293
Members
449,077
Latest member
Rkmenon

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