Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Command Button

I know this probably sounds very simple to most people, but i am new at this!
I would like to create 2 command buttons in a worksheet both doing the same
thing. I would like when each button is clicked the highlighted cells to be
filled in a particular colour. Eg button 1 fills the highlighted cells in
yellow and the second button would fill the highlighted cells in red. Can
anyone help?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Command Button

One way:

Assuming your command buttons are from the Forms Toolbar, attach these
macros to them (right-click them and choose Attach macro):


Public Sub CommandButton1_Click()
Selection.Interior.ColorIndex = 6 'yellow
End Sub

Public Sub CommandButton2_Click()
Selection.Interior.ColorIndex = 3 'red
End Sub


In article ,
"Hardy" wrote:

I know this probably sounds very simple to most people, but i am new at this!
I would like to create 2 command buttons in a worksheet both doing the same
thing. I would like when each button is clicked the highlighted cells to be
filled in a particular colour. Eg button 1 fills the highlighted cells in
yellow and the second button would fill the highlighted cells in red. Can
anyone help?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Command Button

Private Sub Commandbutton1_Click()
Selection.Interior.ColorIndex = 6
End sub

Private Sub Commandbutton2_Click()
Selection.Interior.ColorIndex = 3
end Sub

Make the control toolbox toolbar visible. click on the commandbarbutton and
then rubberband a rectangle on the worksheet.

Repeat for the second button.

Double click on the first button and paste in code like the above in the
resulting module (check that your button names correspond to the code
above. If not, rename the procedures to match the names of your two
buttons.

go back to the worksheet and take the sheet out of design mode (the top left
button on the control toolbox should look depressed. Click it so it isn't).

Now select some cells and click the button.

--
Regards,
Tom Ogilvy

"Hardy" wrote in message
...
I know this probably sounds very simple to most people, but i am new at

this!
I would like to create 2 command buttons in a worksheet both doing the

same
thing. I would like when each button is clicked the highlighted cells to

be
filled in a particular colour. Eg button 1 fills the highlighted cells in
yellow and the second button would fill the highlighted cells in red. Can
anyone help?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Command Button

Hi you need to go to tools VBA edito and right click in the area on your
left where you have "this workbook" and choose insert module (you dont
have to give it a name) and paste the code i have given you there. Now
go back to your excel workbook by clicking the green X at the top left
of your page. Now right click on the tool bar at the top of your excel
page, choose customise, and then commands, scroll down to macros and
drag a custom button on to your tool bar, repeat for your second, now
right click each button in turn and select assign macro at the bottom
and assign buuton1 to the first button etc. You cat work out how to
change the names and pictures of your buttons from the menu you have on
screen.

Hope this helps!

Simon

here's the code!

Option Explicit
Sub button1()
ActiveCell.Select
With Selection.Interior
ColorIndex = 3 'red
Pattern = xlSolid
PatternColorIndex = xlAutomatic
End With
End Sub
Sub button2()
ActiveCell.Select
With Selection.Interior
ColorIndex = 6 'yellow
Pattern = xlSolid
PatternColorIndex = xlAutomatic
End With
End Sub


---
Message posted from http://www.ExcelForum.com/

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
command button add another command Wanna Learn Excel Discussion (Misc queries) 5 December 7th 08 11:42 PM
command button help Lion Excel Discussion (Misc queries) 0 October 22nd 08 06:10 PM
command button on top Todd Huttenstine Excel Programming 1 June 11th 04 07:50 PM
Command Button vs Control Button RGibson Excel Programming 1 October 14th 03 02:24 AM
Command Button vs Form Button T K Excel Programming 4 August 26th 03 07:26 PM


All times are GMT +1. The time now is 05:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"