Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 168
Default OnChange function only when a certain cell changes

Can I do an OnChange function for just one cell? For example, anytime
A1 changes, I'd like to run some code. I don't really want to use the code
on the whole sheet if I don't have to. Can this be done?

Thanks,
Paul


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default OnChange function only when a certain cell changes

Paul,

Forget about OnChange. Instead, use the Worksheet_Change event
procedure (right click on the appropriate sheet tab and choose
View Code). Something like

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
' do something
End If
End Sub



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


"PCLIVE" wrote in message
...
Can I do an OnChange function for just one cell? For
example, anytime A1 changes, I'd like to run some code. I
don't really want to use the code on the whole sheet if I don't
have to. Can this be done?

Thanks,
Paul



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 168
Default OnChange function only when a certain cell changes

Great idea Chip!
Works great!

Thank you,
Paul

"Chip Pearson" wrote in message
...
Paul,

Forget about OnChange. Instead, use the Worksheet_Change event procedure
(right click on the appropriate sheet tab and choose View Code). Something
like

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
' do something
End If
End Sub



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


"PCLIVE" wrote in message
...
Can I do an OnChange function for just one cell? For example, anytime
A1 changes, I'd like to run some code. I don't really want to use the
code on the whole sheet if I don't have to. Can this be done?

Thanks,
Paul





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default OnChange function only when a certain cell changes

I'm glad it works. For more information about events, see
http://www.cpearson.com/excel/events.htm .


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


"PCLIVE" wrote in message
...
Great idea Chip!
Works great!

Thank you,
Paul

"Chip Pearson" wrote in message
...
Paul,

Forget about OnChange. Instead, use the Worksheet_Change event
procedure (right click on the appropriate sheet tab and choose
View Code). Something like

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
' do something
End If
End Sub



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


"PCLIVE" wrote in message
...
Can I do an OnChange function for just one cell? For
example, anytime A1 changes, I'd like to run some code. I
don't really want to use the code on the whole sheet if I
don't have to. Can this be done?

Thanks,
Paul







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default OnChange function only when a certain cell changes

PCLIVE wrote:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
' do something
End If
End Sub



Or

if not intersect (target, range("$A$1")) is nothing then ....


it works if you are intereseted in area larger than single cell i.e.

if not intersect (target, range("$A:$A")) is nothing then ....

entire A column.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default OnChange function only when a certain cell changes

There is no built-in event for a cell change, but the usual way to do what
you want is to test the Target range to see if it includes your cell, e.g:

Sub Worksheet_Change(ByVal Target as Range)
If Not(Intersect(Target, Range("A1")) Is Nothing) Then
' Your code goes here
End If
End Sub

The event procedure runs, but the actual code is skipped if A1 did not change.
--
- K Dales


"PCLIVE" wrote:

Can I do an OnChange function for just one cell? For example, anytime
A1 changes, I'd like to run some code. I don't really want to use the code
on the whole sheet if I don't have to. Can this be done?

Thanks,
Paul



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
ISBLANK function not working when cell is blank dut to function re mcmilja Excel Discussion (Misc queries) 9 May 7th 23 03:43 AM
Workshet onchange Mark Excel Programming 2 August 25th 04 09:12 AM
OnChange Event for a Cell Michael Kintner Excel Programming 3 January 5th 04 08:29 PM
OnChange - argh! How do I get this to work please? mightyginger Excel Programming 1 December 9th 03 12:35 PM
Inserting time stamp onchange of any cell Mitchell Carey Excel Programming 1 August 8th 03 08:09 AM


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