Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default about worksheet_change

Dear all,

I want to start programming a sub when a value in a cell changed, the sub
will be run. How to do it ?

Thanks,
Viesta
  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default about worksheet_change

Right click on your sheet tab, select view code and paste this into the code
window. "MyRange" is a named range that refers to the cell you want to track
(the code will adjust to the user inserting/deleting rows/columns which cause
your cell to move around - VBA doesn't track this like XL formulae do).

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("MyRange")) Is Nothing Then
MsgBox "The cell changed"
Else
MsgBox "The cell did not change"
End If
End Sub



"ViestaWu" wrote:

Dear all,

I want to start programming a sub when a value in a cell changed, the sub
will be run. How to do it ?

Thanks,
Viesta

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default about worksheet_change

Do I need to define the "Myrange" at advanced?

"JMB" wrote:

Right click on your sheet tab, select view code and paste this into the code
window. "MyRange" is a named range that refers to the cell you want to track
(the code will adjust to the user inserting/deleting rows/columns which cause
your cell to move around - VBA doesn't track this like XL formulae do).

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("MyRange")) Is Nothing Then
MsgBox "The cell changed"
Else
MsgBox "The cell did not change"
End If
End Sub



"ViestaWu" wrote:

Dear all,

I want to start programming a sub when a value in a cell changed, the sub
will be run. How to do it ?

Thanks,
Viesta

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default about worksheet_change

worksheet change doesn't need any range restrictions. I can work in every
cell on a worksheet or any combination of cells on a worksheet. the code
below is one way of restricting the cells. Other examples of restrictions


if Target.Row = 5


if Target.Column = 6


if Target.Row = 5 and Target.Column = 3
"ViestaWu" wrote:

Do I need to define the "Myrange" at advanced?

"JMB" wrote:

Right click on your sheet tab, select view code and paste this into the code
window. "MyRange" is a named range that refers to the cell you want to track
(the code will adjust to the user inserting/deleting rows/columns which cause
your cell to move around - VBA doesn't track this like XL formulae do).

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("MyRange")) Is Nothing Then
MsgBox "The cell changed"
Else
MsgBox "The cell did not change"
End If
End Sub



"ViestaWu" wrote:

Dear all,

I want to start programming a sub when a value in a cell changed, the sub
will be run. How to do it ?

Thanks,
Viesta

  #5   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default about worksheet_change

If you want to use the named range, you would select the cell you want to
keep track of, then click in the name box in the top left corner (right above
column A) and type in your range name.

You could use

If Target.Address = "$A$5" Then
instead of
If Not Intersect(Target, Range("MyRange")) Is Nothing Then

but if a row is inserted above row 5, then your cell is now actually A6.
The macro will still be hardcoded to look for cell A5, which is not a problem
if you are certain that cell will not get moved (or are okay w/changing the
code whenever it does move).




"ViestaWu" wrote:

Do I need to define the "Myrange" at advanced?

"JMB" wrote:

Right click on your sheet tab, select view code and paste this into the code
window. "MyRange" is a named range that refers to the cell you want to track
(the code will adjust to the user inserting/deleting rows/columns which cause
your cell to move around - VBA doesn't track this like XL formulae do).

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("MyRange")) Is Nothing Then
MsgBox "The cell changed"
Else
MsgBox "The cell did not change"
End If
End Sub



"ViestaWu" wrote:

Dear all,

I want to start programming a sub when a value in a cell changed, the sub
will be run. How to do it ?

Thanks,
Viesta



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default about worksheet_change

You use a worksheet change macro. The worksheet change is not in a VBA
module, but in VBA worksheet code page. Go to the excel worksheet you want
to run the code, then right click the tab on the bottom of the page (normally
sheet1). Select View Code. Then paste the code below

Sub worksheet_change(ByVal Target As Range)

test = Target

End Sub

"ViestaWu" wrote:

Dear all,

I want to start programming a sub when a value in a cell changed, the sub
will be run. How to do it ?

Thanks,
Viesta

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
?row and ?key -- Worksheet_Change mtnw Excel Programming 2 May 15th 06 07:29 PM
Worksheet_Change Dan Excel Programming 5 November 16th 05 07:37 PM
worksheet_change vs. calculate, and worksheet_change not running Tom Ogilvy Excel Programming 1 July 14th 03 02:51 AM
worksheet_change vs. calculate, and worksheet_change not running Ross[_5_] Excel Programming 0 July 13th 03 04:27 PM


All times are GMT +1. The time now is 09:33 AM.

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"