Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Call Macro when Cell within Range Changes

Hi All,

I understand how to set up a worksheet so that a macro is called when the
value of a specific cell changes (i.e. when Cell A1 changes), but how do you
call a macro when a cell within a range changes (a1:a10).

I know this is simple but I can't find the right arguments?

Any ideas?

Ta

Andi


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Call Macro when Cell within Range Changes

Andi,

Try the following:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("A1:A10")) Is Nothing
Then
' do something
End If
End Sub

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



"Andibevan" wrote
in message ...
Hi All,

I understand how to set up a worksheet so that a macro is
called when the
value of a specific cell changes (i.e. when Cell A1 changes),
but how do you
call a macro when a cell within a range changes (a1:a10).

I know this is simple but I can't find the right arguments?

Any ideas?

Ta

Andi




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Call Macro when Cell within Range Changes

Chip,

Thanks that's perfect. I am slightly confused as I have the following code
which runs a macro when the cell range is selected whereas your macro works
when the cell is changes.

I can see what the difference is but don't understand why swapping the range
and the target round makes such a difference.

Regards

Andi

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Range("A1:A10"), Target) Is Nothing Then
'Call your Macro
Else
End If
End Sub



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

Try the following:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("A1:A10")) Is Nothing
Then
' do something
End If
End Sub

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



"Andibevan" wrote
in message ...
Hi All,

I understand how to set up a worksheet so that a macro is
called when the
value of a specific cell changes (i.e. when Cell A1 changes),
but how do you
call a macro when a cell within a range changes (a1:a10).

I know this is simple but I can't find the right arguments?

Any ideas?

Ta

Andi






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Call Macro when Cell within Range Changes

Andi,

Yours is a SelectionChange event, so will run whenever a cell is selected,
and call you macro if that selection is in A1:A10, whereas Chip's uses the
Change event, so on ly runs when a cell is changed.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Andibevan" wrote in message
...
Chip,

Thanks that's perfect. I am slightly confused as I have the following

code
which runs a macro when the cell range is selected whereas your macro

works
when the cell is changes.

I can see what the difference is but don't understand why swapping the

range
and the target round makes such a difference.

Regards

Andi

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Range("A1:A10"), Target) Is Nothing Then
'Call your Macro
Else
End If
End Sub



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

Try the following:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("A1:A10")) Is Nothing
Then
' do something
End If
End Sub

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



"Andibevan" wrote
in message ...
Hi All,

I understand how to set up a worksheet so that a macro is
called when the
value of a specific cell changes (i.e. when Cell A1 changes),
but how do you
call a macro when a cell within a range changes (a1:a10).

I know this is simple but I can't find the right arguments?

Any ideas?

Ta

Andi








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Call Macro when Cell within Range Changes

Thanks Bob - The answer was staring me in the face. Easy when you know
how..


"Bob Phillips" wrote in message
...
Andi,

Yours is a SelectionChange event, so will run whenever a cell is selected,
and call you macro if that selection is in A1:A10, whereas Chip's uses

the
Change event, so on ly runs when a cell is changed.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Andibevan" wrote in

message
...
Chip,

Thanks that's perfect. I am slightly confused as I have the following

code
which runs a macro when the cell range is selected whereas your macro

works
when the cell is changes.

I can see what the difference is but don't understand why swapping the

range
and the target round makes such a difference.

Regards

Andi

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Range("A1:A10"), Target) Is Nothing

Then
'Call your Macro
Else
End If
End Sub



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

Try the following:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("A1:A10")) Is Nothing
Then
' do something
End If
End Sub

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



"Andibevan" wrote
in message ...
Hi All,

I understand how to set up a worksheet so that a macro is
called when the
value of a specific cell changes (i.e. when Cell A1 changes),
but how do you
call a macro when a cell within a range changes (a1:a10).

I know this is simple but I can't find the right arguments?

Any ideas?

Ta

Andi










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
call range by cell value Roland Excel Worksheet Functions 1 January 15th 09 04:32 PM
Passing a range in a macro call Otto Moehrbach[_6_] Excel Programming 6 November 15th 04 02:31 PM
Call a macro or sub based on the name of a cell? Tom Ogilvy Excel Programming 1 August 26th 03 06:15 PM
Call a macro or sub based on the name of a cell? steve Excel Programming 0 August 25th 03 10:39 PM


All times are GMT +1. The time now is 08:07 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"