Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Run Macro automatically if cell =x

I have created a macro to open a msgbox if the user selects a specific
date from a drop down list. However, currently it will only run if
the user clicks off that cell and then back on it. I want it to run
immediately if the user selects that specific date, or at least run as
soon as they click off that cell (they shouldn't have to click back on
it to get the msgbox to pop up).
The code I am currently using in the specific worksheet is as follows:

Private Sub Worksheet_SelectionChange (ByVal Target as Range)
If Target.Address="$H$4" Then
Application.EnableEvents = True
If Target.Value = "1/4/2008" Or Target.Value =
"2/8/2008" Or Target.Value = "3/7/2008" Or Target.Value = "4/4/2008"
Or Target.Value = "5/9/2008" Or Target.Value = "6/6/2008" Or
Target.Value = "7/4/2008" Or Target.Value = "8/8/2008" Or Target.Value
= "9/5/2008" Or Target.Value = "10/3/2008" Or Target.Value =
"11/7/2008" Or Target.value = "12/5/2008" Then
Msg.Box "This is a New Month,Click 'New Month' Button before
Proceeding"
Range ("H4").Select
Else
End If
End If
End Sub


The Drop Down lists come from named ranges on a different tab that
show up dependant on todays date (If todays date is in the Month of
August, then the August list would appear, if today date is in the
month of November, then the November list would appear).

I also would like to be able to get another macro to run (a simple
sort macro) automatically when the user goes to save the file - usllay
they cahnge the name of the file when they save it).

OK - thats about it for now. Not sure how difficult this task is, but
if anyone can help, I would really appreciate it.
Thanks!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Run Macro automatically if cell =x

Use Worksheet_Change instead of SelectionChange
Private Sub Worksheet_Change(ByVal Target As Range)

As for resorting on save, use the BeforeSave event of the ThisWorkbook
module.

bjohnson wrote:
I have created a macro to open a msgbox if the user selects a specific
date from a drop down list. However, currently it will only run if
the user clicks off that cell and then back on it. I want it to run
immediately if the user selects that specific date, or at least run as
soon as they click off that cell (they shouldn't have to click back on
it to get the msgbox to pop up).
The code I am currently using in the specific worksheet is as follows:

Private Sub Worksheet_SelectionChange (ByVal Target as Range)
If Target.Address="$H$4" Then
Application.EnableEvents = True
If Target.Value = "1/4/2008" Or Target.Value =
"2/8/2008" Or Target.Value = "3/7/2008" Or Target.Value = "4/4/2008"
Or Target.Value = "5/9/2008" Or Target.Value = "6/6/2008" Or
Target.Value = "7/4/2008" Or Target.Value = "8/8/2008" Or Target.Value
= "9/5/2008" Or Target.Value = "10/3/2008" Or Target.Value =
"11/7/2008" Or Target.value = "12/5/2008" Then
Msg.Box "This is a New Month,Click 'New Month' Button before
Proceeding"
Range ("H4").Select
Else
End If
End If
End Sub


The Drop Down lists come from named ranges on a different tab that
show up dependant on todays date (If todays date is in the Month of
August, then the August list would appear, if today date is in the
month of November, then the November list would appear).

I also would like to be able to get another macro to run (a simple
sort macro) automatically when the user goes to save the file - usllay
they cahnge the name of the file when they save it).

OK - thats about it for now. Not sure how difficult this task is, but
if anyone can help, I would really appreciate it.
Thanks!


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
run macro automatically when cell content is changed? Kathrine Excel Worksheet Functions 1 March 22nd 07 10:44 PM
Macro: automatically initiating upon cell click pmp613 Excel Discussion (Misc queries) 1 December 28th 06 09:46 AM
how do I automatically run a macro from the result of a cell Barrie Lewis Excel Programming 1 April 11th 06 12:12 PM
Run macro automatically when a cell in a dynamic range changes [email protected] Excel Programming 6 August 9th 05 09:54 AM
Automatically run a macro when a cell = FALSE Jonathan Neubauer[_2_] Excel Programming 2 January 31st 05 09:28 AM


All times are GMT +1. The time now is 05:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"