Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Cell update to run macro

I have a worksheet that has around 20 non-contiguous cells where we need to
enter data. Then I want to run a vba macro each time the data in any of these
cells is changed. Can someone tell me how to trigger the vba routine from a
cell update?
Thanks,
RD Wirr
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Cell update to run macro

You could use a change event to do this eg:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRange As Range
Dim junct As Range
On Error GoTo ErrorHandler
Application.EnableEvents = False
Set myRange = Union(Range("A1"), Range("B4"), Range("C7")) 'etc
Set junct = Intersect(Target, myRange)
If Not junct Is Nothing Then
Call YourMacro
End If
ErrorHandler:
Application.EnableEvents = True
End Sub

This is worksheet event code. Right click the sheet tab, select View Code
and paste the code in there. Change the union statement to include the
relevant cells (it will only take 30). Alternately you could manually select
the relevant cells and define them to a named range: Insert Name Define.
The code could then look like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRange As Range
Dim junct As Range
On Error GoTo ErrorHandler
Application.EnableEvents = False
Set myRange = Range("NamedRange")
Set junct = Intersect(Target, myRange)
If Not junct Is Nothing Then
Call YourMacro
End If
ErrorHandler:
Application.EnableEvents = True
End Sub

Hope this helps
Rowan

"RD Wirr" wrote:

I have a worksheet that has around 20 non-contiguous cells where we need to
enter data. Then I want to run a vba macro each time the data in any of these
cells is changed. Can someone tell me how to trigger the vba routine from a
cell update?
Thanks,
RD Wirr

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Cell update to run macro


One way to do this is to check the address/location of the updating cel
to determine if it is the cell you want to process...

Assuming you only want to process changes in cells A5, C7, and J10, yo
can do:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$5" Then
'process cell A5
ElseIf Target.Address = "$C$7" Then
'process cell C7
ElseIf (Target.Row = 10) And (Target.Column = 10) Then
'process cell J10
End If
End Sub


RD Wirr Wrote:
I have a worksheet that has around 20 non-contiguous cells where we nee
to
enter data. Then I want to run a vba macro each time the data in any o
these
cells is changed. Can someone tell me how to trigger the vba routin
from a
cell update?
Thanks,
RD Wir


--
T-Že
-----------------------------------------------------------------------
T-Žex's Profile: http://www.excelforum.com/member.php...fo&userid=2657
View this thread: http://www.excelforum.com/showthread.php?threadid=40067

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
Update Cell in Multiple Sheets - Macro enna49 Excel Worksheet Functions 2 March 5th 10 04:05 AM
Data Validation lists update orginal cell with list update [email protected] Excel Worksheet Functions 3 July 11th 08 07:56 AM
need help to update macro to office 2007 macro enabled workbook jatman Excel Discussion (Misc queries) 1 December 14th 07 01:57 PM
Update Macro: Leave Colour As Before Once Cell is Not Active JB2010 Excel Discussion (Misc queries) 2 February 2nd 06 06:08 PM
Selection.Replace doesn't update the cell value in macro! Nasser Hosseini Excel Programming 1 February 26th 04 07:41 PM


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