![]() |
Allow Macro to Work by Selecting Cell Description
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 |
Allow Macro to Work by Selecting Cell Description
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 |
Allow Macro to Work by Selecting Cell Description
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 |
Allow Macro to Work by Selecting Cell Description
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 |
Allow Macro to Work by Selecting Cell Description
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 |
All times are GMT +1. The time now is 05:27 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com