Looping through and coloring cell

alx1056

New Member
Joined
Jul 11, 2018
Messages
8
Hello,

I have some data that I want to color once a button is clicked. I want it to go to the next cell and stop once the cell contains an empty string.

Here is my code:

Code:
Private Sub CommandButton1_Click()
    Dim C As Variant
    
    Range("A1").Select
    
    C = ActiveCell.Offset(1, 0).Value
    
    Do
        ActiveCell.Offset(1, 0).Select
        C.Interior.Color = vbMagenta
         
    Loop While ActiveCell.Value <> " "
    

End Sub


I keep getting an error of: "Run-Time Error 424 object required.

Thanks!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
c is the value of the cell, yet you are treating it like a range object.

Try this:
Code:
Private Sub CommandButton1_Click()

    Dim r as Long

    r = 1
    Do Until Cells(r, "A") = ""
        Cells(r, "A").Interior.Color = vbMagenta
        r = r + 1
    Loop

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

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