Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Automatic Macros Invocation

The code for my sub is as listed below:-

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyRange As Range
Set MyRange = Range(Cells(1, "a"), Cells(2, "b"))
If Target.Address = Range("MyRange").Address Then
Cells(1, "c") = Cells(1, "a") * Cells(1, "b")
Cells(2, "c") = Cells(2, "a") + Cells(2, "b")
End If
End Sub


I am trying to automatically invoke the macros when the values in the cells
for MyRange are changed.
..

I am getting a runtime error '1004'


Can anyone help me, please




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 179
Default Automatic Macros Invocation

pthien

Range("MyRange") is not valid. It should be

If Target.Address = MyRange.Address Then

Also, the SelectionChange event fires when the a cell is selected, not when
it's changed. You may want the Worksheet_Change event.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"pthien" wrote in message
...
The code for my sub is as listed below:-

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyRange As Range
Set MyRange = Range(Cells(1, "a"), Cells(2, "b"))
If Target.Address = Range("MyRange").Address Then
Cells(1, "c") = Cells(1, "a") * Cells(1, "b")
Cells(2, "c") = Cells(2, "a") + Cells(2, "b")
End If
End Sub


I am trying to automatically invoke the macros when the values in the

cells
for MyRange are changed.
.

I am getting a runtime error '1004'


Can anyone help me, please






  #3   Report Post  
Posted to microsoft.public.excel.programming
jaf jaf is offline
external usenet poster
 
Posts: 300
Default Automatic Macros Invocation

Hi,
The cells function takes numeric arguments not letters.

Set MyRange = Range(Cells(1, 1), Cells(2, 2))
If Target.Address = Range("MyRange").Address Then
Cells(1, 3) = Cells(1, 1) * Cells(1, 2)
Cells(2, 3) = Cells(2, 1) + Cells(2, 2)



--

John

johnf202 at hotmail dot com


"pthien" wrote in message
...
The code for my sub is as listed below:-

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyRange As Range
Set MyRange = Range(Cells(1, "a"), Cells(2, "b"))
If Target.Address = Range("MyRange").Address Then
Cells(1, "c") = Cells(1, "a") * Cells(1, "b")
Cells(2, "c") = Cells(2, "a") + Cells(2, "b")
End If
End Sub


I am trying to automatically invoke the macros when the values in the

cells
for MyRange are changed.
.

I am getting a runtime error '1004'


Can anyone help me, please






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 179
Default Automatic Macros Invocation

John

That's not true. The ColumnIndex argument is a Variant that takes numbers
and letters. Check out help for the Item property of the Range object.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"jaf" wrote in message
...
Hi,
The cells function takes numeric arguments not letters.

Set MyRange = Range(Cells(1, 1), Cells(2, 2))
If Target.Address = Range("MyRange").Address Then
Cells(1, 3) = Cells(1, 1) * Cells(1, 2)
Cells(2, 3) = Cells(2, 1) + Cells(2, 2)



--

John

johnf202 at hotmail dot com


"pthien" wrote in message
...
The code for my sub is as listed below:-

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyRange As Range
Set MyRange = Range(Cells(1, "a"), Cells(2, "b"))
If Target.Address = Range("MyRange").Address Then
Cells(1, "c") = Cells(1, "a") * Cells(1, "b")
Cells(2, "c") = Cells(2, "a") + Cells(2, "b")
End If
End Sub


I am trying to automatically invoke the macros when the values in the

cells
for MyRange are changed.
.

I am getting a runtime error '1004'


Can anyone help me, please








  #5   Report Post  
Posted to microsoft.public.excel.programming
jaf jaf is offline
external usenet poster
 
Posts: 300
Default Automatic Macros Invocation

Hi Dick,
I was thinking strings not variables, but I see I would have been wrong
about that too.


--

John

johnf202 at hotmail dot com


"Dick Kusleika" wrote in message
...
John

That's not true. The ColumnIndex argument is a Variant that takes numbers
and letters. Check out help for the Item property of the Range object.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"jaf" wrote in message
...
Hi,
The cells function takes numeric arguments not letters.

Set MyRange = Range(Cells(1, 1), Cells(2, 2))
If Target.Address = Range("MyRange").Address Then
Cells(1, 3) = Cells(1, 1) * Cells(1, 2)
Cells(2, 3) = Cells(2, 1) + Cells(2, 2)



--

John

johnf202 at hotmail dot com


"pthien" wrote in message
...
The code for my sub is as listed below:-

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyRange As Range
Set MyRange = Range(Cells(1, "a"), Cells(2, "b"))
If Target.Address = Range("MyRange").Address Then
Cells(1, "c") = Cells(1, "a") * Cells(1, "b")
Cells(2, "c") = Cells(2, "a") + Cells(2, "b")
End If
End Sub


I am trying to automatically invoke the macros when the values in the

cells
for MyRange are changed.
.

I am getting a runtime error '1004'


Can anyone help me, please












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
Automatic Macros David Fredrickson Excel Worksheet Functions 2 April 20th 09 05:50 PM
Macros warning always shows up, even if all macros removed Joe M Excel Discussion (Misc queries) 1 December 20th 07 04:45 AM
How to enable macros and automatic calculation on Excel Viewer? David Excel Worksheet Functions 2 April 5th 07 08:53 PM
Training: More on how to use macros in Excel: Recording Macros ToriT Excel Worksheet Functions 2 February 10th 06 07:05 PM
Excel 2002 Automatic Macros CM[_4_] Excel Programming 1 July 17th 03 12:57 AM


All times are GMT +1. The time now is 06:26 AM.

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"