Run macro from Data validation result

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,604
Office Version
  1. 365
Platform
  1. Windows
Quick question...

Data validation box sits in cell A1

whatever the use selects from the list I want 'macro1' to run

any ideas??

thanks
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "A1" Then
    Application.EnableEvents = False
    Call Macro1
    Application.EnableEvents = True
End If
End Sub
 
Upvote 0
having trouble with this :(

The date validation list sits in cell ref G10
I want the following code to run when a name is chosen from that list.

My current code is this...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$G$10" Then
Application.ScreenUpdating = False

'Clear old data first
    Sheets("Lateness database").Select
    Range("E15:G150").Select
    Selection.ClearContents
    Range("E15").Select
    
'Get new selected data from filter
    Sheets("Lateness data").Select
    Columns("A:D").Select
    Selection.AutoFilter Field:=1, Criteria1:=Sheets("Lateness database").Range("G10")
    Selection.Copy
    Sheets("Lateness database").Select
    Range("D14").Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    Range("A7").Select

End If
End Sub

but the code breaks at ..

Code:
Columns("A:D").Select

however if I run the code above usining a button..it works fine!!

any ideas??
 
Upvote 0
Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$G$10" Then
Application.ScreenUpdating = False

'Clear old data first
    Sheets("Lateness database").Range("E15:G150").ClearContents
'Get new selected data from filter
    Sheets("Lateness data").Columns("A:D").AutoFilter Field:=1, Criteria1:=Sheets("Lateness database").Range("G10")
    Sheets("Lateness data").Columns("A:D").Copy
    Sheets("Lateness database").Range("D14").PasteSpecial Paste:=xlValues
End If
End Sub
 
Upvote 0
Should be

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$G$10" Then
Application.ScreenUpdating = False

'Clear old data first
    Sheets("Lateness database").Range("E15:G150").ClearContents
'Get new selected data from filter
    Sheets("Lateness data").Columns("A:D").AutoFilter Field:=1, Criteria1:=Sheets("Lateness database").Range("G10")
    Sheets("Lateness data").Columns("A:D").SpecialCells(xlCellTypeVisible).Copy
    Sheets("Lateness database").Range("D14").PasteSpecial Paste:=xlValues
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,421
Members
452,913
Latest member
JWD210

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