Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 56
Default run macro if cell value changes

I'm trying to run the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
Range("C65536").End(xlUp).Offset(1, 0) = Range("B1") + Target
If Range("C65536").End(xlUp).Address = "$C$10" _
Then Range("$C$2").Delete Shift:=xlUp

End If
End Sub

The value of A1 changes automatically (the outcome of a function), because
of this, the above mentioned code doesn't run.
Is it correct to use the 'change event' code, as described below, to make
the above mentioned code recognise that the value of A1 is changed?
If so, how do i intergrate both codes?

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "B2" Then
Dim Blank_count As Integer
etc
etc
End If
End Sub


thanks very much for all help!

Maurice
Amsterdam, The Netherlands
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 903
Default run macro if cell value changes

Hi Maurice,

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False 'should be part of Change macro
IF .... then
...
ElseIF .... then
...
ElseIF .... then
...
Else 'not needed with what you posted...

End IF
Application.EnableEvents = True 'should be part of Change macro
End Sub

See you VBA Help for IF then Else statement

If your macro terminates without reenabling events
you might need to run a macro like that found in
http://www.mvps.org/dmcritchie/excel/event.htm#problems
Sub Fix_Things()
Application.DisplayAlerts = True
Application.EnableEvents = True 'should be part of Change macro
End Sub ---HTH, David McRitchie, Microsoft MVP - Excel My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htmSearch
Page: http://www.mvps.org/dmcritchie/excel/search.htm "Maurice" wrote in message
...
I'm trying to run the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
Range("C65536").End(xlUp).Offset(1, 0) = Range("B1") + Target
If Range("C65536").End(xlUp).Address = "$C$10" _
Then Range("$C$2").Delete Shift:=xlUp

End If
End Sub

The value of A1 changes automatically (the outcome of a function), because
of this, the above mentioned code doesn't run.
Is it correct to use the 'change event' code, as described below, to make
the above mentioned code recognise that the value of A1 is changed?
If so, how do i intergrate both codes?

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "B2" Then
Dim Blank_count As Integer
etc
etc
End If
End Sub


thanks very much for all help!

Maurice
Amsterdam, The Netherlands



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 56
Default run macro if cell value changes

Thanks David, but i am practically new to vba, and i am not sure how to
proceed.

"David McRitchie" wrote:

Hi Maurice,

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False 'should be part of Change macro
IF .... then
...
ElseIF .... then
...
ElseIF .... then
...
Else 'not needed with what you posted...

End IF
Application.EnableEvents = True 'should be part of Change macro
End Sub

See you VBA Help for IF then Else statement

If your macro terminates without reenabling events
you might need to run a macro like that found in
http://www.mvps.org/dmcritchie/excel/event.htm#problems
Sub Fix_Things()
Application.DisplayAlerts = True
Application.EnableEvents = True 'should be part of Change macro
End Sub ---HTH, David McRitchie, Microsoft MVP - Excel My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htmSearch
Page: http://www.mvps.org/dmcritchie/excel/search.htm "Maurice" wrote in message
...
I'm trying to run the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
Range("C65536").End(xlUp).Offset(1, 0) = Range("B1") + Target
If Range("C65536").End(xlUp).Address = "$C$10" _
Then Range("$C$2").Delete Shift:=xlUp

End If
End Sub

The value of A1 changes automatically (the outcome of a function), because
of this, the above mentioned code doesn't run.
Is it correct to use the 'change event' code, as described below, to make
the above mentioned code recognise that the value of A1 is changed?
If so, how do i intergrate both codes?

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "B2" Then
Dim Blank_count As Integer
etc
etc
End If
End Sub


thanks very much for all help!

Maurice
Amsterdam, The Netherlands




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 if cell value changes Brettjg Excel Discussion (Misc queries) 2 March 28th 07 12:02 AM
macro to move part of cell contents to another cell icetoad hisself Excel Discussion (Misc queries) 4 November 27th 06 07:19 PM
using a cell value to control a counter inside a macro and displaying macro value ocset Excel Worksheet Functions 1 September 10th 06 05:32 AM
Using macro to copy a part of a cell content to next cell Charles Excel Discussion (Misc queries) 6 May 31st 06 05:57 AM
Macro for cell selection starting with Last Cell Valerie Excel Worksheet Functions 4 December 9th 05 08:25 PM


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