PC Review


Reply
Thread Tools Rate Thread

Automatic calling of a macro

 
 
Michelle
Guest
Posts: n/a
 
      15th Jan 2008
Hello all!

I would like to know if there is a way to call a macro to run when a
particular cell, say A1 on Sheet1 for ease, is changed. A1 will be changed
by a formula calculation, not by a user hard coding an input. I currently
have a button to call the macro and do its thing, but I would like to
streamline the worksheet a bit. I know that I found a solution to this
problem somewhere on here previously, but I've been looking for the
particular post for a while with no luck. I'm hoping that somebody could
help me out with this. Any help would be much appreciated. Thanks in
advance.

--
Cheers,
Michelle
"Anyone who says he can see through women is missing a lot." Groucho Marx
 
Reply With Quote
 
 
 
 
Gord Dibben
Guest
Posts: n/a
 
      15th Jan 2008
Private Sub Worksheet_Calculate()
On Error GoTo stoppit
Application.EnableEvents = False
With Me.Range("A1")
If .Value <> "" Then
Call macroname
End If
End With
stoppit:
Application.EnableEvents = True
End Sub


Gord Dibben MS Excel MVP

On Tue, 15 Jan 2008 11:00:03 -0800, Michelle
<(E-Mail Removed)> wrote:

>Hello all!
>
>I would like to know if there is a way to call a macro to run when a
>particular cell, say A1 on Sheet1 for ease, is changed. A1 will be changed
>by a formula calculation, not by a user hard coding an input. I currently
>have a button to call the macro and do its thing, but I would like to
>streamline the worksheet a bit. I know that I found a solution to this
>problem somewhere on here previously, but I've been looking for the
>particular post for a while with no luck. I'm hoping that somebody could
>help me out with this. Any help would be much appreciated. Thanks in
>advance.


 
Reply With Quote
 
Michelle
Guest
Posts: n/a
 
      15th Jan 2008
Thank you very much. That works like a charm. Would you mind explaining
your code to me so I understand what is going on? Not sure I see what is
going on. Thanks.

--
Cheers,
Michelle
"Anyone who says he can see through women is missing a lot." Groucho Marx


"Gord Dibben" wrote:

> Private Sub Worksheet_Calculate()
> On Error GoTo stoppit
> Application.EnableEvents = False
> With Me.Range("A1")
> If .Value <> "" Then
> Call macroname
> End If
> End With
> stoppit:
> Application.EnableEvents = True
> End Sub
>
>
> Gord Dibben MS Excel MVP
>
> On Tue, 15 Jan 2008 11:00:03 -0800, Michelle
> <(E-Mail Removed)> wrote:
>
> >Hello all!
> >
> >I would like to know if there is a way to call a macro to run when a
> >particular cell, say A1 on Sheet1 for ease, is changed. A1 will be changed
> >by a formula calculation, not by a user hard coding an input. I currently
> >have a button to call the macro and do its thing, but I would like to
> >streamline the worksheet a bit. I know that I found a solution to this
> >problem somewhere on here previously, but I've been looking for the
> >particular post for a while with no luck. I'm hoping that somebody could
> >help me out with this. Any help would be much appreciated. Thanks in
> >advance.

>
>

 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      15th Jan 2008
>> Private Sub Worksheet_Calculate()
type of event is on calculate
>> On Error GoTo stoppit

self-explanatory use of On Error to do something if an error takes place
>> Application.EnableEvents = False

events are disabled to prevent infinite looping
>> With Me.Range("A1")

looks at A1 in Me, which is same as ActiveSheet or Sheets("Sheetname")
>> If .Value <> "" Then

if A1 is not blank then the macro is called
>> Call macroname
>> End If

had an If above so now end that because the macro was called successfully
>> End With

the job has been done so we release A1 and operation of this event code
>> stoppit:
>> Application.EnableEvents = True

re-enable events so they can run again on this or any other sheet or workbook
>> End Sub


For more on events see Chip Pearson's site

http://www.cpearson.com/excel/Events.aspx

Check out especially the section on "Order of Events"


Gord

On Tue, 15 Jan 2008 11:37:03 -0800, Michelle
<(E-Mail Removed)> wrote:

>Thank you very much. That works like a charm. Would you mind explaining
>your code to me so I understand what is going on? Not sure I see what is
>going on. Thanks.
>
>--
>Cheers,
>Michelle
>"Anyone who says he can see through women is missing a lot." Groucho Marx
>
>
>"Gord Dibben" wrote:
>
>> Private Sub Worksheet_Calculate()
>> On Error GoTo stoppit
>> Application.EnableEvents = False
>> With Me.Range("A1")
>> If .Value <> "" Then
>> Call macroname
>> End If
>> End With
>> stoppit:
>> Application.EnableEvents = True
>> End Sub


 
Reply With Quote
 
Michelle
Guest
Posts: n/a
 
      16th Jan 2008
Thank you for taking time to explain that to me. It was very helpful. I
hadn't really done anything with events yet.

--
Cheers,
Michelle
"Anyone who says he can see through women is missing a lot." Groucho Marx


"Gord Dibben" wrote:

> >> Private Sub Worksheet_Calculate()

> type of event is on calculate
> >> On Error GoTo stoppit

> self-explanatory use of On Error to do something if an error takes place
> >> Application.EnableEvents = False

> events are disabled to prevent infinite looping
> >> With Me.Range("A1")

> looks at A1 in Me, which is same as ActiveSheet or Sheets("Sheetname")
> >> If .Value <> "" Then

> if A1 is not blank then the macro is called
> >> Call macroname
> >> End If

> had an If above so now end that because the macro was called successfully
> >> End With

> the job has been done so we release A1 and operation of this event code
> >> stoppit:
> >> Application.EnableEvents = True

> re-enable events so they can run again on this or any other sheet or workbook
> >> End Sub

>
> For more on events see Chip Pearson's site
>
> http://www.cpearson.com/excel/Events.aspx
>
> Check out especially the section on "Order of Events"
>
>
> Gord

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro calling a Tab Bill Microsoft Access Macros 1 23rd Jun 2008 02:00 AM
Calling a public Macro from a Private Macro =?Utf-8?B?dGhld2l6eg==?= Microsoft Excel Programming 6 2nd Nov 2007 10:23 PM
Calling XLA Macro from DLL. =?Utf-8?B?VCBH?= Microsoft Excel Programming 3 21st Nov 2006 07:37 AM
macro calling another macro + variables =?Utf-8?B?eW8=?= Microsoft Excel Misc 2 5th Apr 2006 04:36 PM
how to disable a macro by calling it from another macro paritoshmehta Microsoft Excel Programming 5 6th May 2004 07:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:32 AM.