Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default how do you make a macro run automatically when a criteria is met?

I am trying to set up a marco that is run automatically if a certian word is
put into a certian cell in a workbook is this possible?

Many thanks
Lee
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default how do you make a macro run automatically when a criteria is met?

you could use the change event.

Right click on the sheet tab, select view code and paste in code like this
(adjusted for your actuall cell/word/macro to run)

Private Sub Worksheet_Change(ByVal Target As Range)
Static bFlag As Boolean
If Target.Count 1 Then Exit Sub
If Target.Address = "$B$9" Then
If Target.Value = "Goofy" Then
If Not bFlag Then
mymacro
bFlag = True
End If
Else
bFlag = False
End If
End If
End Sub

Chip Pearson's page on events:
http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy



"Lee Crew" wrote:

I am trying to set up a marco that is run automatically if a certian word is
put into a certian cell in a workbook is this possible?

Many thanks
Lee

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default how do you make a macro run automatically when a criteria is met?

Hi Tom,

I'm just a beginner in this stuff
why don't use smple way like :

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target = "My word" Then My Macro
End Sub

Just asking ...
Thanks,

Halim


Tom Ogilvy wrote:
you could use the change event.

Right click on the sheet tab, select view code and paste in code like this
(adjusted for your actuall cell/word/macro to run)

Private Sub Worksheet_Change(ByVal Target As Range)
Static bFlag As Boolean
If Target.Count 1 Then Exit Sub
If Target.Address = "$B$9" Then
If Target.Value = "Goofy" Then
If Not bFlag Then
mymacro
bFlag = True
End If
Else
bFlag = False
End If
End If
End Sub

Chip Pearson's page on events:
http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy



"Lee Crew" wrote:

I am trying to set up a marco that is run automatically if a certian word is
put into a certian cell in a workbook is this possible?

Many thanks
Lee


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default how do you make a macro run automatically when a criteria is m

SelectionChange fires when the cell is selected. If the user entered My
word, the macro would not be fired until the user reselected the cell. Then,
after it had fired, it would fire again each time the user selected the cell
(and its value remained My word) and it would fire everytime the user
selected any cell that contained My word. If the user selected several cells
your code would raise a type mismatch error. So the smple way you suggested
doesn't answer the requested functionality and is flawed.

--
Regards,
Tom Ogilvy


"halim" wrote:

Hi Tom,

I'm just a beginner in this stuff
why don't use smple way like :

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target = "My word" Then My Macro
End Sub

Just asking ...
Thanks,

Halim


Tom Ogilvy wrote:
you could use the change event.

Right click on the sheet tab, select view code and paste in code like this
(adjusted for your actuall cell/word/macro to run)

Private Sub Worksheet_Change(ByVal Target As Range)
Static bFlag As Boolean
If Target.Count 1 Then Exit Sub
If Target.Address = "$B$9" Then
If Target.Value = "Goofy" Then
If Not bFlag Then
mymacro
bFlag = True
End If
Else
bFlag = False
End If
End If
End Sub

Chip Pearson's page on events:
http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy



"Lee Crew" wrote:

I am trying to set up a marco that is run automatically if a certian word is
put into a certian cell in a workbook is this possible?

Many thanks
Lee



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
How can make a macro to run evey one hour-automatically SAM SEBAIHI Excel Discussion (Misc queries) 2 January 30th 07 04:12 AM
How do I make a section sort automatically? Wicus Excel Discussion (Misc queries) 1 May 19th 06 05:00 PM
How do I make a macro automatically select Yes when a yes/no box appears? JasonK[_2_] Excel Programming 4 April 3rd 06 02:48 PM
How to make a macro that automatically starts after clicking a cel Samirkc Excel Programming 1 February 17th 06 12:31 PM
Make a macro run automatically in Excel 03??? Rob Excel Programming 1 June 29th 05 07:29 PM


All times are GMT +1. The time now is 06:28 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"