Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
command button add another command | Excel Discussion (Misc queries) | |||
command button help | Excel Discussion (Misc queries) | |||
command button on top | Excel Programming | |||
Command Button vs Control Button | Excel Programming | |||
Command Button vs Form Button | Excel Programming |