Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Newbie's macro doesn't appear to work!

Can someone please explain why this little macro won't work?

TIA
Len
_____________

Dim Msg

Private Sub Worksheet_Change(ByVal Target As Range)
Msg = "You must NOT check your own work!"
If Target.Column < 6 Or Target.Column < 9 Then Exit Sub
If Target.Column = 6 And Target = Target.Offset(0, -1) Then
MsgBox (Msg)
End If
If Target.Column = 9 And Target = Target.Offset(0, -2) Then
MsgBox (Msg)
End If
End Sub



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Newbie's macro doesn't appear to work!

Len,

It is helpful if you describe what specific problem you are having with the
procedure -- e.g., what is does do that it shouldn't or what it doesn't do
that it should -- rather than simply saying that is doesn't work.

I suspect that your problem is with the line

If Target.Column < 6 Or Target.Column < 9 Then Exit Sub

Here, you will exit the sub regardless of what the value of Target.Column
is. If Target.Column = 6, then "Target.Column = 9" will return True, and you
will exit the sub. Similarly, if Target.Column = 9, then "Target.Column =
6" will return True and you will exit the sub. Finally, if Target.Value =
any other number, but conditionals will return True and you will exit the
sub.

You should change the "Or" to an "And". E.g.,

If Target.Column < 6 And Target.Column < 9 Then Exit Sub

In this case, you will exit the sub if Target.Column is any value other than
6 or 9.


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



"evillen" wrote in message
...
Can someone please explain why this little macro won't work?

TIA
Len
_____________

Dim Msg

Private Sub Worksheet_Change(ByVal Target As Range)
Msg = "You must NOT check your own work!"
If Target.Column < 6 Or Target.Column < 9 Then Exit Sub
If Target.Column = 6 And Target = Target.Offset(0, -1) Then
MsgBox (Msg)
End If
If Target.Column = 9 And Target = Target.Offset(0, -2) Then
MsgBox (Msg)
End If
End Sub



------------------------------------------------
~~ Message posted from
http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Newbie's macro doesn't appear to work!

Hi Chip

Sorry about not putting more detail - you are quite right about that
and you were also correct with your analysis of my syntax problem.

Many thanks
Len



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly 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
Macro to sum doesn't work RM270 Excel Discussion (Misc queries) 2 March 17th 10 05:55 PM
Macro to update a column in a work based on another work sheet WickerMan New Users to Excel 1 December 4th 09 12:58 PM
Macro works Macro does not work Wanna Learn Excel Discussion (Misc queries) 4 March 24th 08 12:51 PM
Why Won't This Macro Work? Pausert of Nikkeldepaiin Excel Discussion (Misc queries) 7 February 4th 08 01:05 PM
how do you get (end down) to work in a macro? lcx2 Excel Worksheet Functions 1 March 24th 05 08:15 AM


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