Another Command button doubt...

G

Guest

Hi to all!

Here you have another question about a macro...

I need to change the fill color of some cells by clicking a command button.
I've searched VB help but I haven0t found anything.

If anyone knows the correct code please write it...

Thanks to all!
 
D

Dave Peterson

Try recording a macro when you change the selected cell's fill color.

Then stop recording.

Then add a commandbutton from the control toolbar toolbox to the worksheet.

Double click on that commandbutton and you'll see where you want to move the
code.

Then delete the original recorded macro.

When you're done, you should end up with a routine that looks like:

Option Explicit
Private Sub CommandButton1_Click()
Selection.Interior.ColorIndex = 35
End Sub

The number will depend on what color you use.
 
G

Guest

the simplest way
if it is always the same cells you want changed,
record a macro changing them
it will be something like

Sub colcel()
Range("D6,F12,H7").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
End Sub

assign a button to that macro
change color index to get the color you want

if you want to select the cells then change them
try

Sub colcel1()
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
End Sub

if you need the macro to select the cells, what is your criteria?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top