#1   Report Post  
mowen
 
Posts: n/a
Default Macro not running


Why wouldn't this macro work when I copy it to the module?

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$j$2" Then
On Error Resume Next
Application.EnableEvents = False
Me.Name = Target.Value
Application.EnableEvents = True
End If
End Sub

Rune


--
mowen
------------------------------------------------------------------------
mowen's Profile: http://www.excelforum.com/member.php...fo&userid=8463
View this thread: http://www.excelforum.com/showthread...hreadid=466759

  #2   Report Post  
Jim Cone
 
Posts: n/a
Default

mowen,

Because the Target.Address does not equal "$j$2".
Either change the lowercase j to upper case or add
"Option Compare Text" to the top of the module.

Jim Cone
San Francisco, USA


"mowen"

wrote in message

Why wouldn't this macro work when I copy it to the module?
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$j$2" Then
On Error Resume Next
Application.EnableEvents = False
Me.Name = Target.Value
Application.EnableEvents = True
End If
End Sub
Rune
mowen
  #3   Report Post  
Dave Peterson
 
Posts: n/a
Default

Or you could use a different way to check:

If Target.Address = "$J$2" Then

is equivalent to these two lines:

if target.cells.count 1 then exit sub
if intersect(target, me.range("j2")) is nothing then exit sub



mowen wrote:

Why wouldn't this macro work when I copy it to the module?

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$j$2" Then
On Error Resume Next
Application.EnableEvents = False
Me.Name = Target.Value
Application.EnableEvents = True
End If
End Sub

Rune

--
mowen
------------------------------------------------------------------------
mowen's Profile: http://www.excelforum.com/member.php...fo&userid=8463
View this thread: http://www.excelforum.com/showthread...hreadid=466759


--

Dave Peterson
  #4   Report Post  
mowen
 
Posts: n/a
Default


This code have work before and yes I have now change to upper case.
For me its looks like I have placed it wrong, because when I try to run
the macro the Macro windows pop up and want me to write the macro name
and make a new macro.
Rune


--
mowen
------------------------------------------------------------------------
mowen's Profile: http://www.excelforum.com/member.php...fo&userid=8463
View this thread: http://www.excelforum.com/showthread...hreadid=466759

  #5   Report Post  
Dave Peterson
 
Posts: n/a
Default

This kind of procedure doesn't get run by the user running the macro
(tools|macro|macros...).

It gets run by the user making a change in the worksheet.

So rightclick on the worksheet tab that should have this behavior. Select View
code and paste your corrected code into that code window.

(And clean up whereever the code was before.)

Then back to excel and change J2 to see what happens.

mowen wrote:

This code have work before and yes I have now change to upper case.
For me its looks like I have placed it wrong, because when I try to run
the macro the Macro windows pop up and want me to write the macro name
and make a new macro.
Rune

--
mowen
------------------------------------------------------------------------
mowen's Profile: http://www.excelforum.com/member.php...fo&userid=8463
View this thread: http://www.excelforum.com/showthread...hreadid=466759


--

Dave Peterson
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
Running a macro for each item in an Autofilter list Andrew Excel Discussion (Misc queries) 1 August 19th 05 02:39 PM
How to CANCEL file SAVE PROMPT when MACRO is running? Stuart Macro Muppet Excel Discussion (Misc queries) 3 August 11th 05 12:26 PM
Prevent A Macro From Running If SpreadSheet is Filtered carl Excel Worksheet Functions 1 June 22nd 05 04:04 PM
How to stop getting the file save box when running a macro Pank Mehta Excel Discussion (Misc queries) 1 March 29th 05 04:05 PM
Shadows of the Pivottable Field List while macro is running David P Excel Worksheet Functions 0 February 25th 05 07:11 PM


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