Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Could you please help me with this matter?
I have a three buttons with their respectively macros in one worksheet. The macros names are Wood, Metal and Plastic. In addition, I have a pull out list located in the cell A1 with the following description: Wood Metal Plastic I would like to know if I can just run the macros name with its respectively name pulled out in the list. For example, I pick in the cell A1 Wood I just want the macro Wood be able to run after I click it. If I click the button with the macro Metal and/or the macro Plastic I want to get a window message €śPick the Wood Button€ť. For example, I pick in the cell A1 Metal I just want the macro Metal be able to run after I click it. If I click the button with the macro Wood and/or the macro Plastic I want to get a window message €śPick the Metal Button€ť. For example, I pick in the cell A1 Plastic I just want the macro Plastic be able to run after I click it. If I click the button with the macro Wood and/or the macro Metal I want to get a window message €śPick the Plastic Button€ť. Thanks in advance. Maperalia |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
There are several ways to do this. Here's two:
First: Create a new function in the same module as your macros Private Function ValidMaterialSelected(ByVal sMacroMaterial As String) As Boolean Dim sMaterialSelected As String sMaterialSelected = Range("a1").Value If sMacroMaterial = sMaterialSelected Then ValidMaterialSelected = True Else MsgBox "Pick the " & sMaterialSelected & " button." ValidMaterialSelected = False End If End Function Then, at the beginning of each of your macros, add the following code: if not ValidSelectedMaterial( [the name of your macro ie Wood, Metal, Plastic]) then exit sub end if Second way: Create only one button on your sheet that would trigger the following code: application.run range("a1") This will launch the macro whose name is in A1. By the way, I didn't test the code. PA "Maperalia" wrote: Could you please help me with this matter? I have a three buttons with their respectively macros in one worksheet. The macros names are Wood, Metal and Plastic. In addition, I have a pull out list located in the cell A1 with the following description: Wood Metal Plastic I would like to know if I can just run the macros name with its respectively name pulled out in the list. For example, I pick in the cell A1 Wood I just want the macro Wood be able to run after I click it. If I click the button with the macro Metal and/or the macro Plastic I want to get a window message €śPick the Wood Button€ť. For example, I pick in the cell A1 Metal I just want the macro Metal be able to run after I click it. If I click the button with the macro Wood and/or the macro Plastic I want to get a window message €śPick the Metal Button€ť. For example, I pick in the cell A1 Plastic I just want the macro Plastic be able to run after I click it. If I click the button with the macro Wood and/or the macro Metal I want to get a window message €śPick the Plastic Button€ť. Thanks in advance. Maperalia |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
sPA;
Thanks very much. Your code runs excellent. Maperalia "PA" wrote: There are several ways to do this. Here's two: First: Create a new function in the same module as your macros Private Function ValidMaterialSelected(ByVal sMacroMaterial As String) As Boolean Dim sMaterialSelected As String sMaterialSelected = Range("a1").Value If sMacroMaterial = sMaterialSelected Then ValidMaterialSelected = True Else MsgBox "Pick the " & sMaterialSelected & " button." ValidMaterialSelected = False End If End Function Then, at the beginning of each of your macros, add the following code: if not ValidSelectedMaterial( [the name of your macro ie Wood, Metal, Plastic]) then exit sub end if Second way: Create only one button on your sheet that would trigger the following code: application.run range("a1") This will launch the macro whose name is in A1. By the way, I didn't test the code. PA "Maperalia" wrote: Could you please help me with this matter? I have a three buttons with their respectively macros in one worksheet. The macros names are Wood, Metal and Plastic. In addition, I have a pull out list located in the cell A1 with the following description: Wood Metal Plastic I would like to know if I can just run the macros name with its respectively name pulled out in the list. For example, I pick in the cell A1 Wood I just want the macro Wood be able to run after I click it. If I click the button with the macro Metal and/or the macro Plastic I want to get a window message €śPick the Wood Button€ť. For example, I pick in the cell A1 Metal I just want the macro Metal be able to run after I click it. If I click the button with the macro Wood and/or the macro Plastic I want to get a window message €śPick the Metal Button€ť. For example, I pick in the cell A1 Plastic I just want the macro Plastic be able to run after I click it. If I click the button with the macro Wood and/or the macro Metal I want to get a window message €śPick the Plastic Button€ť. Thanks in advance. Maperalia |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
When a button is pressed, check if the corresponding text is selected in A1, if not display message and exit sub. Otherwise continue code. Private Sub cbPlastic_Click() If Range("A1").Value < "Plastic" Then msg = MsgBox("Pick the " & Range("A1").Value & " button!", vbExclamation, "Wrong Button") Exit Sub End If 'Your code End Sub Hopes this helps. --- Per "Maperalia" skrev i meddelelsen ... Could you please help me with this matter? I have a three buttons with their respectively macros in one worksheet. The macros names are Wood, Metal and Plastic. In addition, I have a pull out list located in the cell A1 with the following description: Wood Metal Plastic I would like to know if I can just run the macros name with its respectively name pulled out in the list. For example, I pick in the cell A1 Wood I just want the macro Wood be able to run after I click it. If I click the button with the macro Metal and/or the macro Plastic I want to get a window message €śPick the Wood Button€ť. For example, I pick in the cell A1 Metal I just want the macro Metal be able to run after I click it. If I click the button with the macro Wood and/or the macro Plastic I want to get a window message €śPick the Metal Button€ť. For example, I pick in the cell A1 Plastic I just want the macro Plastic be able to run after I click it. If I click the button with the macro Wood and/or the macro Metal I want to get a window message €śPick the Plastic Button€ť. Thanks in advance. Maperalia |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Per;
Thanks you very much. It is working PERFECTLY!!!!!! Maperalia "Per Jessen" wrote: Hi When a button is pressed, check if the corresponding text is selected in A1, if not display message and exit sub. Otherwise continue code. Private Sub cbPlastic_Click() If Range("A1").Value < "Plastic" Then msg = MsgBox("Pick the " & Range("A1").Value & " button!", vbExclamation, "Wrong Button") Exit Sub End If 'Your code End Sub Hopes this helps. --- Per "Maperalia" skrev i meddelelsen ... Could you please help me with this matter? I have a three buttons with their respectively macros in one worksheet. The macros names are Wood, Metal and Plastic. In addition, I have a pull out list located in the cell A1 with the following description: Wood Metal Plastic I would like to know if I can just run the macros name with its respectively name pulled out in the list. For example, I pick in the cell A1 Wood I just want the macro Wood be able to run after I click it. If I click the button with the macro Metal and/or the macro Plastic I want to get a window message €śPick the Wood Button€ť. For example, I pick in the cell A1 Metal I just want the macro Metal be able to run after I click it. If I click the button with the macro Wood and/or the macro Plastic I want to get a window message €śPick the Metal Button€ť. For example, I pick in the cell A1 Plastic I just want the macro Plastic be able to run after I click it. If I click the button with the macro Wood and/or the macro Metal I want to get a window message €śPick the Plastic Button€ť. Thanks in advance. Maperalia |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Selecting a cell during a macro | Excel Programming | |||
Selecting a cell doesn't work????? | Excel Programming | |||
Macro - Selecting Next Available Cell | Excel Programming | |||
Data Validation does not work when selecting another cell. | Excel Discussion (Misc queries) | |||
Macro selecting the last used cell does not work | Excel Programming |