Select the Name in the Data Validation list on a cell value then the same name run the sub macro

kpmsivaprakasam2003

New Member
Joined
Jan 28, 2020
Messages
14
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Platform
  1. Windows
Excel VBA code is required to Select the Name in the Data Validation list on a cell value after the same name could be run in the sub macro.

E.g. Data Validation List assigned in "Sheet3" cell text value "B2". if I select the "AA" and then Call to "AA" Sub Marco run. I got error the code line "Application.Run Text".

Below Excel VBA code here: Excel version is 2013

Private Sub Worksheet_Change(ByVal Target As Range)
'Run Macro when Drop Down value selected
'VBA to run from Data Validation
'Auto Show Drop-Down List When Selecting the Cell
If Target.CountLarge > 1 Then Exit Sub

If Target.Address = Range("B2").Address Then
Application.EnableEvents = False

Dim Text As String
Text = ThisWorkbook.Sheets("Sheet3").Range("B2").Value
Application.Run Text

'or

'If Target.Address = "$A$1" Then
'Call ThisWorkbook.Sheets("Sheet3").Range("B2").Value
'End If
End If

Application.EnableEvents = True
End Sub


Public Sub AA()
MsgBox "AA Macro"
End Sub


Public Sub BB()
MsgBox "BB Macro"
End Sub


Public Sub CC()
MsgBox "CC Macro"
End Sub


Thanks for Advance
Sivapraakasam K
 

Attachments

  • Untitled.png
    Untitled.png
    122.3 KB · Views: 11

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
You must remove the following code from the sheet code and put it in a module.

VBA Code:
Public Sub AA()
MsgBox "AA Macro"
End Sub

Public Sub BB()
MsgBox "BB Macro"
End Sub

Public Sub CC()
MsgBox "CC Macro"
End Sub

Regards
Dante Amor
 
Upvote 0
You must remove the following code from the sheet code and put it in a module.

VBA Code:
Public Sub AA()
MsgBox "AA Macro"
End Sub

Public Sub BB()
MsgBox "BB Macro"
End Sub

Public Sub CC()
MsgBox "CC Macro"
End Sub

Regards
Dante Amor
Thanks for reply, but, not working in a module
 
Upvote 0
A reminder

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem. However, this is the third time you have done it, with no acknowledgement on any occasion; if you do it again, you will be banned.
 
Last edited:
Upvote 0
If it is written in a worksheet module,
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address(0, 0) <> "B2" Then Exit Sub
    If Target <> "" Then Run Me.CodeName & "." & Target
End Sub
 
Upvote 0
A reminder

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem. However, this is the third time you have done it, with no acknowledgement on any occasion; if you do it again, you will be banned.
ohh okay, sorry late . . .
 
Upvote 0
You must remove the following code from the sheet code and put it in a module.

VBA Code:
Public Sub AA()
MsgBox "AA Macro"
End Sub

Public Sub BB()
MsgBox "BB Macro"
End Sub

Public Sub CC()
MsgBox "CC Macro"
End Sub

Regards
Dante Amor
You can put an image to see how you have the code on the sheet and in the module.

View attachment 116270

It works well for me.

🤗
Yes! It's working. Thanks for clearing me, sorry for late view . . .
 
Upvote 0

Forum statistics

Threads
1,224,847
Messages
6,181,313
Members
453,031
Latest member
Chris_1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top