Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default Cell Change activating macro. How do you make it happen?

Hi

I have a situation where I would like to activate a macro after a change in the contents
of a single cell. I know that this can be done for applications and worksheets, but can
someone tell me how to make it happen for a single cell. Note that I am not very good at
VBA coding, so any details would be helpful.

Thanks

John Baker
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default Cell Change activating macro. How do you make it happen?

John,

You can use the Worksheet_Change event procedure and test which cell was
changed. For example,

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$2" Then
MsgBox "Do something "
End If
End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"John Baker" wrote in message
...
Hi

I have a situation where I would like to activate a macro after a change

in the contents
of a single cell. I know that this can be done for applications and

worksheets, but can
someone tell me how to make it happen for a single cell. Note that I am

not very good at
VBA coding, so any details would be helpful.

Thanks

John Baker



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default Cell Change activating macro. How do you make it happen?

Chip:

Thanks. I Tried this (using the appropriate cell designation), and it didn't work when set
up as a macro. It also didn't work when set up as a VBA item. Is the problem that i need
to execute it in the startup (to make it active), or is it that it doesn't point to the
actual sheet (name "input) where the cell at interest resides?

Thanks a lot for your help on this.

regards

John Baker
"Chip Pearson" wrote:

John,

You can use the Worksheet_Change event procedure and test which cell was
changed. For example,

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$2" Then
MsgBox "Do something "
End If
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Cell Change activating macro. How do you make it happen?

It is event code

Right click on the worksheet tab where you want this behavior. Select View
code.

Paste in the code.

--
Regards,
Tom Ogilvy

"John Baker" wrote in message
...
Chip:

Thanks. I Tried this (using the appropriate cell designation), and it

didn't work when set
up as a macro. It also didn't work when set up as a VBA item. Is the

problem that i need
to execute it in the startup (to make it active), or is it that it doesn't

point to the
actual sheet (name "input) where the cell at interest resides?

Thanks a lot for your help on this.

regards

John Baker
"Chip Pearson" wrote:

John,

You can use the Worksheet_Change event procedure and test which cell was
changed. For example,

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$2" Then
MsgBox "Do something "
End If
End Sub




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default Cell Change activating macro. How do you make it happen?

Tom:

Thanks for the advice.

The following is exactly what I pasted into the worksheet code sheet:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Address = "$f$5" Then
Msg box "Do something "
End If
End Sub

However, nothing happens when I change the contents of F5 and press enter! When I change
the cell contents, press enter, leave the cell, and then later return and click on it the
"DO SOMETHING" box activates.

Is this the way its supposed to happen?


"Tom Ogilvy" wrote:

It is event code

Right click on the worksheet tab where you want this behavior. Select View
code.

Paste in the code.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default Cell Change activating macro. How do you make it happen?

John,

The problem is most likely the comparison with the address: by default, VBA
does case sensitive comparisons, and Address will return $F$5 and your code
has $f$5. At the very top of the code module, before any procedure or
declaration, include

Option Compare Text


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"John Baker" wrote in message
...
Tom:

Thanks for the advice.

The following is exactly what I pasted into the worksheet code sheet:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Address = "$f$5" Then
Msg box "Do something "
End If
End Sub

However, nothing happens when I change the contents of F5 and press enter!

When I change
the cell contents, press enter, leave the cell, and then later return and

click on it the
"DO SOMETHING" box activates.

Is this the way its supposed to happen?


"Tom Ogilvy" wrote:

It is event code

Right click on the worksheet tab where you want this behavior. Select

View
code.

Paste in the code.




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Cell Change activating macro. How do you make it happen?

John,

It doesn't work as intended because you use Worksheet_SelectionChange instead of Worksheet_Change as Chip wrote.

HTH
Anders Silven


"John Baker" skrev i meddelandet ...
Tom:

Thanks for the advice.

The following is exactly what I pasted into the worksheet code sheet:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Address = "$f$5" Then
Msg box "Do something "
End If
End Sub

However, nothing happens when I change the contents of F5 and press enter! When I change
the cell contents, press enter, leave the cell, and then later return and click on it the
"DO SOMETHING" box activates.

Is this the way its supposed to happen?


"Tom Ogilvy" wrote:

It is event code

Right click on the worksheet tab where you want this behavior. Select View
code.

Paste in the code.


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Cell Change activating macro. How do you make it happen?

Hi John,

Right-click on the sheet tab in question and select 'View Code'. In
the VBE paste in the following code:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address < "$A$1" Then Exit Sub
Call ARoutine
End Sub

And in a general module (eg Module1) paste the routine to be called:

Sub ARoutine()
MsgBox "Your macro here!"
End Sub

Just change the A1 reference to the cell of your choice and amend
ARoutine to the routine in question.

HTH
Richie

John Baker wrote in message . ..
Hi

I have a situation where I would like to activate a macro after a change in the contents
of a single cell. I know that this can be done for applications and worksheets, but can
someone tell me how to make it happen for a single cell. Note that I am not very good at
VBA coding, so any details would be helpful.

Thanks

John Baker

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default Cell Change activating macro. How do you make it happen?

Guys:

I am embarrassed to ask this, but here goes.

The suggestions you all have made work magnificently, but I have found that there are TWO
cells that need to trigger the SAME macro when they change (the month and the year). I
tried putting in a second copy of the macro in on the worksheet level, pointing to the
second cell, but it complained that it was a duplicate name (quite justly). I tried
various combinations to refer to the two cells F5 and F6, but none of them worked.

How do I refer to two adjacent cells in the formula you gave me?

Thanks again

John Baker

(Richie UK) wrote:

Hi John,

Right-click on the sheet tab in question and select 'View Code'. In
the VBE paste in the following code:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address < "$A$1" Then Exit Sub
Call ARoutine
End Sub

And in a general module (eg Module1) paste the routine to be called:

Sub ARoutine()
MsgBox "Your macro here!"
End Sub

Just change the A1 reference to the cell of your choice and amend
ARoutine to the routine in question.

HTH
Richie

John Baker wrote in message . ..
Hi

I have a situation where I would like to activate a macro after a change in the contents
of a single cell. I know that this can be done for applications and worksheets, but can
someone tell me how to make it happen for a single cell. Note that I am not very good at
VBA coding, so any details would be helpful.

Thanks

John Baker




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Cell Change activating macro. How do you make it happen?

I not intersect(Target,Range("F5:F6")) is nothing then


End if

--
Regards,
Tom Ogilvy

John Baker wrote in message
...
Guys:

I am embarrassed to ask this, but here goes.

The suggestions you all have made work magnificently, but I have found

that there are TWO
cells that need to trigger the SAME macro when they change (the month and

the year). I
tried putting in a second copy of the macro in on the worksheet level,

pointing to the
second cell, but it complained that it was a duplicate name (quite

justly). I tried
various combinations to refer to the two cells F5 and F6, but none of them

worked.

How do I refer to two adjacent cells in the formula you gave me?

Thanks again

John Baker

(Richie UK) wrote:

Hi John,

Right-click on the sheet tab in question and select 'View Code'. In
the VBE paste in the following code:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address < "$A$1" Then Exit Sub
Call ARoutine
End Sub

And in a general module (eg Module1) paste the routine to be called:

Sub ARoutine()
MsgBox "Your macro here!"
End Sub

Just change the A1 reference to the cell of your choice and amend
ARoutine to the routine in question.

HTH
Richie

John Baker wrote in message

. ..
Hi

I have a situation where I would like to activate a macro after a

change in the contents
of a single cell. I know that this can be done for applications and

worksheets, but can
someone tell me how to make it happen for a single cell. Note that I am

not very good at
VBA coding, so any details would be helpful.

Thanks

John Baker




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
What do I need to add to my macro to make the cell colors change Bojames Excel Discussion (Misc queries) 4 July 22nd 08 03:52 PM
TRUE/FALSE BOX not activating a WS change Jase Excel Discussion (Misc queries) 1 April 11th 08 07:42 PM
Activating a Macro d_kight New Users to Excel 5 June 30th 06 07:46 PM
How do I make this happen m@ Excel Worksheet Functions 3 June 25th 06 10:52 PM
Can I make some thing happen if I get a "reminder" BruceJ[_2_] Excel Programming 1 November 6th 03 09:11 AM


All times are GMT +1. The time now is 05:23 PM.

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"