Use CommandButton to Cycle/ Loop color of cell

noexcelguru

New Member
Joined
Jan 18, 2011
Messages
40
The idea is to change the Interior.Color of a cell by using one CommandButton
I've tried different variants of MyPlage and Dim in fustration because i can't find any related works here or with google
And what's the difference between Cycle and Loop?

The closest I got;

Private Sub CommandButton17_Click()
Dim i As Integer
Case xlNone
Cell.Interior.ColorIndex = 3

Next i
Cell.Interior.ColorIndex = 6

Next i
Cell.Interior.ColorIndex = 4

Next i
Cell.Interior.ColorIndex = xlNone
End Selected
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Are you trying to loop through set colours by clicking the macro to change it?
If so, try this (untested):-
Code:
Private Sub CommandButton17_Click()
Select case cell.interior.colorindex
    case xlnone: Cell.Interior.ColorIndex = 3
    case 3: Cell.Interior.ColorIndex = 6
    case 6: Cell.Interior.ColorIndex = 4
    case 4: Cell.Interior.ColorIndex = xlnone
End Select
End Sub
 
Upvote 0
Thanks, RichardMGreen, but i get the message "object requried" and yellow marking at: Select case cell.interior.colorindex
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

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