Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Automate a macro based on the value of a cell? (call Sub)

Here it is:

1. I have a muti-sheet workbook

2. I have buttons on several sheets that call Subroutines
that assign default values -- they work fine.

The problem: How can I run one of those macros/Sub
automatically when some cell goes, say TRUE to FALSE?

Specifically, from Sheet1 I want to run the code attached
to Button2 on Sheet2.

Help,

Doug
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Automate a macro based on the value of a cell? (call Sub)

Hi
you need an event procedure for this. E.g. use the worksheet change
event for this. Put the following code in your worksheet module (tests
cell A1):

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("A1")) Is Nothing Then Exit Sub
On Error GoTo CleanUp:
With Target
If .value then
Application.EnableEvents = False
' enter your code or call a different sub
end if
End With

CleanUp:
Application.EnableEvents = True
End Sub


--
Regards
Frank Kabel
Frankfurt, Germany

Douglas wrote:
Here it is:

1. I have a muti-sheet workbook

2. I have buttons on several sheets that call Subroutines
that assign default values -- they work fine.

The problem: How can I run one of those macros/Sub
automatically when some cell goes, say TRUE to FALSE?

Specifically, from Sheet1 I want to run the code attached
to Button2 on Sheet2.

Help,

Doug


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Automate a macro based on the value of a cell? (call Sub)

Unless the change from True to False is done by DDE or through a user making
a change in a cell, you probably want to use the calculate event. If you
don't want the macro to run everytime a calculate occurs, you would have to
add code to maintain what the last state of the cell was to see it it was
changed in this calculate.

--
Regards,
Tom Ogilvy

"Frank Kabel" wrote in message
...
Hi
you need an event procedure for this. E.g. use the worksheet change
event for this. Put the following code in your worksheet module (tests
cell A1):

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("A1")) Is Nothing Then Exit Sub
On Error GoTo CleanUp:
With Target
If .value then
Application.EnableEvents = False
' enter your code or call a different sub
end if
End With

CleanUp:
Application.EnableEvents = True
End Sub


--
Regards
Frank Kabel
Frankfurt, Germany

Douglas wrote:
Here it is:

1. I have a muti-sheet workbook

2. I have buttons on several sheets that call Subroutines
that assign default values -- they work fine.

The problem: How can I run one of those macros/Sub
automatically when some cell goes, say TRUE to FALSE?

Specifically, from Sheet1 I want to run the code attached
to Button2 on Sheet2.

Help,

Doug




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Frank & Tom -- Thanks!

You've given me hope -- I'll try it later

Doug


-----Original Message-----
Hi
you need an event procedure for this. E.g. use the

worksheet change
event for this. Put the following code in your worksheet

module (tests
cell A1):

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("A1")) Is Nothing Then

Exit Sub
On Error GoTo CleanUp:
With Target
If .value then
Application.EnableEvents = False
' enter your code or call a different sub
end if
End With

CleanUp:
Application.EnableEvents = True
End Sub


--
Regards
Frank Kabel
Frankfurt, Germany

Douglas wrote:
Here it is:

1. I have a muti-sheet workbook

2. I have buttons on several sheets that call

Subroutines
that assign default values -- they work fine.

The problem: How can I run one of those macros/Sub
automatically when some cell goes, say TRUE to FALSE?

Specifically, from Sheet1 I want to run the code

attached
to Button2 on Sheet2.

Help,

Doug


.

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
Excel code to call a macro when a certain value in a cell isselected. [email protected] Excel Worksheet Functions 4 February 15th 08 08:18 PM
Macro to automate page protection based on combo box reply wongard Excel Discussion (Misc queries) 9 September 9th 05 06:47 AM
Call a macro or sub based on the name of a cell? Tom Ogilvy Excel Programming 1 August 26th 03 06:15 PM
Call a macro or sub based on the name of a cell? steve Excel Programming 0 August 25th 03 10:39 PM


All times are GMT +1. The time now is 01:02 PM.

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

About Us

"It's about Microsoft Excel"