Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default running a macro when cemm contents change

I have four cells a10,a20,a30 & a40 and I want to run a different set o
commands when the contents of any of these 4 cells change i.e. if th
contents of a10 change copy a10 to b10, but if the contents of a2
change copy a20 to b20 and so o

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default running a macro when cemm contents change

Mark,

Your description is slightly different to your request. Let me clarify. You
say that you want to run different commands depending upon which cell is
change. But what you describe is the same command, but with a different
target, but one that is similaolrly aliugned. SZo in it's simplest form
this will work

This is worksheet code, so it goes in the worksheet code module.

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
On Error GoTo ws_exit
If Not Intersect(Target, Range("A10,A20,A30,A40")) Is Nothing Then
With Target
.Offset(0, 1).Value = .Value
End With
End If
ws_exit:
Application.EnableEvents = True
End Sub

If however, you do need different commands, it is better to structure the
code like this

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
On Error GoTo ws_exit
If Not Intersect(Target, Range("A10,A20,A30,A40")) Is Nothing Then
With Target
Select Case .Address
Case "$A$10": Range("B10") = .Value
Case "$A$20": Range("B20") = .Value
Case "$A$30": Range("B30") = .Value
Case "$A$40": Range("B40") = .Value
End Select
End With
End If
ws_exit:
Application.EnableEvents = True
End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"markshowell " wrote in message
...
I have four cells a10,a20,a30 & a40 and I want to run a different set of
commands when the contents of any of these 4 cells change i.e. if the
contents of a10 change copy a10 to b10, but if the contents of a20
change copy a20 to b20 and so on


---
Message posted from http://www.ExcelForum.com/



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
VBA Macro change column contents James C[_2_] Excel Discussion (Misc queries) 4 January 25th 10 02:36 PM
Running a macro on cell value change Brettjg Excel Discussion (Misc queries) 2 March 28th 07 02:55 PM
Running a macro on cell value change Mike Excel Discussion (Misc queries) 0 March 28th 07 01:13 AM
Running a macro on cell value change Brettjg Excel Discussion (Misc queries) 0 March 28th 07 12:08 AM
Run macro when cell contents change Tim Smith Excel Programming 3 September 27th 03 06:44 PM


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