English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have three buttons in the worksheet, if is put the button name (ex. 6 for button6) in any cell, it shoule excute the things what button 6 would execute

2007-09-05 16:51:19 · 1 answers · asked by Nithin R 1 in Computers & Internet Programming & Design

1 answers

Hi,
I have written following 4 subroutine in the same module.
The last subroutine (Sub Worksheet_Change) has been written to track any changes made in the active sheet. Whenever u write any thing in this worksheet, it will be executed and the cell address will be passed to the subroutine. There u capture the cell value by writing Target.Value. If Target.Value is one (1) then code written under command button1 is executed. Similarly for value 2 and 3.

------------------------------------------------------------------------------
Private Sub CommandButton1_Click()
MsgBox "I am 1."
'put ur code for command button 1.
End Sub

Private Sub CommandButton2_Click()
MsgBox "I am 2."
'put ur code for command button 2.
End Sub

Private Sub CommandButton3_Click()
MsgBox "I am 3."
'put ur code for command button 3.
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Value
Case 1
CommandButton1_Click
Case 2
CommandButton2_Click
Case 3
CommandButton3_Click
End Select
End Sub
------------------------------------------------------------------------------

2007-09-05 18:30:30 · answer #1 · answered by iqbal 4 · 0 0

fedest.com, questions and answers