PC Review


Reply
Thread Tools Rate Thread

conflict in code somewhere

 
 
Jock
Guest
Posts: n/a
 
      12th Oct 2009
Hi,
The following code works in a Worksheet_Change (ByVal Target As Range) event:

' Displays message box when "C" is selected in H
Dim Res3 As VbMsgBoxResult
If Not Intersect(Target, Me.Range("H4:H4000")) Is Nothing Then
With Target
If Target.Value = "C" Then
If Target.Offset(, -1) = "" Then
Application.EnableEvents = False
Res3 = MsgBox("No account has been selected!", vbOKOnly, "Charging of
accounts")
Target.Value = vbNullString
Else
Res3 = MsgBox("Is this item to be charged to an account?", vbYesNo,
"Charging of accounts")
If Res3 = vbNo Then
Target.Value = vbNullString
Else
UserForm7.Show
End If
Application.EnableEvents = True
End If
End If

When another function is added to the same Worksheet_Change code, the second
one (below) doesn't work.

However, if the first one is removed, it works fine:

' when date entered in "K", checks "H"
Dim Res4 As VbMsgBoxResult
Const Myrange3 = "K4:K4000"
If Not Intersect(Target, Me.Range("K4:K4000")) Is Nothing Then
Exit Sub
End If
If IsDate(Target) And Target.Offset(, -3) = "" Or Target.Offset(, -3)
= "N" Then
Application.EnableEvents = False
Res4 = MsgBox("Cannot issue claim without payment!")
Target.ClearContents
Application.EnableEvents = True
End If


The first code above is currently at the end of about 4 pages of other code
in Sheet!1 all of which works ok until the second one is added.
I have three other subs to add but until I can figure out why they don't
work, when added in, I am stuck.


Can I have a second Worksheet_Change event to put these into or can they be
placed in ThisWorkbook or in a module?
Help!
Thanks in advance.
--
Traa Dy Liooar

Jock
 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      12th Oct 2009
you use
WITH target
there's ne end with and you don't use any of Target's properties.
you dim a const but don't use it.

what error messages do you get
put
OPTION EXPLICIT
at the top of the module, then from the menu select DEBUG/COMPILE

you can only have one event handler for a given event. Ideally, the event
code shoudl be quite short, or it should call procedures in a general Module
- this enable other sheet events to use the same code etc etc











"Jock" wrote:

> Hi,
> The following code works in a Worksheet_Change (ByVal Target As Range) event:
>
> ' Displays message box when "C" is selected in H
> Dim Res3 As VbMsgBoxResult
> If Not Intersect(Target, Me.Range("H4:H4000")) Is Nothing Then
> With Target
> If Target.Value = "C" Then
> If Target.Offset(, -1) = "" Then
> Application.EnableEvents = False
> Res3 = MsgBox("No account has been selected!", vbOKOnly, "Charging of
> accounts")
> Target.Value = vbNullString
> Else
> Res3 = MsgBox("Is this item to be charged to an account?", vbYesNo,
> "Charging of accounts")
> If Res3 = vbNo Then
> Target.Value = vbNullString
> Else
> UserForm7.Show
> End If
> Application.EnableEvents = True
> End If
> End If
>
> When another function is added to the same Worksheet_Change code, the second
> one (below) doesn't work.
>
> However, if the first one is removed, it works fine:
>
> ' when date entered in "K", checks "H"
> Dim Res4 As VbMsgBoxResult
> Const Myrange3 = "K4:K4000"
> If Not Intersect(Target, Me.Range("K4:K4000")) Is Nothing Then
> Exit Sub
> End If
> If IsDate(Target) And Target.Offset(, -3) = "" Or Target.Offset(, -3)
> = "N" Then
> Application.EnableEvents = False
> Res4 = MsgBox("Cannot issue claim without payment!")
> Target.ClearContents
> Application.EnableEvents = True
> End If
>
>
> The first code above is currently at the end of about 4 pages of other code
> in Sheet!1 all of which works ok until the second one is added.
> I have three other subs to add but until I can figure out why they don't
> work, when added in, I am stuck.
>
>
> Can I have a second Worksheet_Change event to put these into or can they be
> placed in ThisWorkbook or in a module?
> Help!
> Thanks in advance.
> --
> Traa Dy Liooar
>
> Jock

 
Reply With Quote
 
Jock
Guest
Posts: n/a
 
      12th Oct 2009
Hi Patrick,
I don't get any error messages - that's half my problem. If I did, I could
wrestle with it.
The 'end with' is there, I missed it when copying the code though.
Rather than use Target, is there another option?
tbh, I'm a bit confused as I have a number of workbooks which do different
things and I have put this one together using code from the other
spreadsheets and from posts on this forum.
Unfortunately, I don't understand enough to sort it out!
Thanks,

--
Traa Dy Liooar

Jock


"Patrick Molloy" wrote:

> you use
> WITH target
> there's ne end with and you don't use any of Target's properties.
> you dim a const but don't use it.
>
> what error messages do you get
> put
> OPTION EXPLICIT
> at the top of the module, then from the menu select DEBUG/COMPILE
>
> you can only have one event handler for a given event. Ideally, the event
> code shoudl be quite short, or it should call procedures in a general Module
> - this enable other sheet events to use the same code etc etc
>
>
>
>
>
>
>
>
>
>
>
> "Jock" wrote:
>
> > Hi,
> > The following code works in a Worksheet_Change (ByVal Target As Range) event:
> >
> > ' Displays message box when "C" is selected in H
> > Dim Res3 As VbMsgBoxResult
> > If Not Intersect(Target, Me.Range("H4:H4000")) Is Nothing Then
> > With Target
> > If Target.Value = "C" Then
> > If Target.Offset(, -1) = "" Then
> > Application.EnableEvents = False
> > Res3 = MsgBox("No account has been selected!", vbOKOnly, "Charging of
> > accounts")
> > Target.Value = vbNullString
> > Else
> > Res3 = MsgBox("Is this item to be charged to an account?", vbYesNo,
> > "Charging of accounts")
> > If Res3 = vbNo Then
> > Target.Value = vbNullString
> > Else
> > UserForm7.Show
> > End If
> > Application.EnableEvents = True
> > End If
> > End If
> >
> > When another function is added to the same Worksheet_Change code, the second
> > one (below) doesn't work.
> >
> > However, if the first one is removed, it works fine:
> >
> > ' when date entered in "K", checks "H"
> > Dim Res4 As VbMsgBoxResult
> > Const Myrange3 = "K4:K4000"
> > If Not Intersect(Target, Me.Range("K4:K4000")) Is Nothing Then
> > Exit Sub
> > End If
> > If IsDate(Target) And Target.Offset(, -3) = "" Or Target.Offset(, -3)
> > = "N" Then
> > Application.EnableEvents = False
> > Res4 = MsgBox("Cannot issue claim without payment!")
> > Target.ClearContents
> > Application.EnableEvents = True
> > End If
> >
> >
> > The first code above is currently at the end of about 4 pages of other code
> > in Sheet!1 all of which works ok until the second one is added.
> > I have three other subs to add but until I can figure out why they don't
> > work, when added in, I am stuck.
> >
> >
> > Can I have a second Worksheet_Change event to put these into or can they be
> > placed in ThisWorkbook or in a module?
> > Help!
> > Thanks in advance.
> > --
> > Traa Dy Liooar
> >
> > Jock

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      12th Oct 2009
I would write this:

If IsDate(Target) And Target.Offset(, -3) = "" Or Target.Offset(, -3)
= "N" Then

Like this:

If IsDate(Target) And Target.Offset(, -3) = "" Then
If Target.Offset(, -3) = "N" Then
'rest of statement
End If
End If




"Jock" <(E-Mail Removed)> wrote in message
news:3ED52ECC-F28E-4595-8B2F-(E-Mail Removed)...
> Hi,
> The following code works in a Worksheet_Change (ByVal Target As Range)
> event:
>
> ' Displays message box when "C" is selected in H
> Dim Res3 As VbMsgBoxResult
> If Not Intersect(Target, Me.Range("H4:H4000")) Is Nothing Then
> With Target
> If Target.Value = "C" Then
> If Target.Offset(, -1) = "" Then
> Application.EnableEvents = False
> Res3 = MsgBox("No account has been selected!", vbOKOnly, "Charging of
> accounts")
> Target.Value = vbNullString
> Else
> Res3 = MsgBox("Is this item to be charged to an account?",
> vbYesNo,
> "Charging of accounts")
> If Res3 = vbNo Then
> Target.Value = vbNullString
> Else
> UserForm7.Show
> End If
> Application.EnableEvents = True
> End If
> End If
>
> When another function is added to the same Worksheet_Change code, the
> second
> one (below) doesn't work.
>
> However, if the first one is removed, it works fine:
>
> ' when date entered in "K", checks "H"
> Dim Res4 As VbMsgBoxResult
> Const Myrange3 = "K4:K4000"
> If Not Intersect(Target, Me.Range("K4:K4000")) Is Nothing Then
> Exit Sub
> End If
> If IsDate(Target) And Target.Offset(, -3) = "" Or
> Target.Offset(, -3)
> = "N" Then
> Application.EnableEvents = False
> Res4 = MsgBox("Cannot issue claim without payment!")
> Target.ClearContents
> Application.EnableEvents = True
> End If
>
>
> The first code above is currently at the end of about 4 pages of other
> code
> in Sheet!1 all of which works ok until the second one is added.
> I have three other subs to add but until I can figure out why they don't
> work, when added in, I am stuck.
>
>
> Can I have a second Worksheet_Change event to put these into or can they
> be
> placed in ThisWorkbook or in a module?
> Help!
> Thanks in advance.
> --
> Traa Dy Liooar
>
> Jock



 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      12th Oct 2009
Disregard that. Try this:

If Target.Offset(, 3) = "" Or Target.Offset(, 3) = N Then
If IsDate(Target) Then
'Rest of statement
End If
End If


"Jock" <(E-Mail Removed)> wrote in message
news:3ED52ECC-F28E-4595-8B2F-(E-Mail Removed)...
> Hi,
> The following code works in a Worksheet_Change (ByVal Target As Range)
> event:
>
> ' Displays message box when "C" is selected in H
> Dim Res3 As VbMsgBoxResult
> If Not Intersect(Target, Me.Range("H4:H4000")) Is Nothing Then
> With Target
> If Target.Value = "C" Then
> If Target.Offset(, -1) = "" Then
> Application.EnableEvents = False
> Res3 = MsgBox("No account has been selected!", vbOKOnly, "Charging of
> accounts")
> Target.Value = vbNullString
> Else
> Res3 = MsgBox("Is this item to be charged to an account?",
> vbYesNo,
> "Charging of accounts")
> If Res3 = vbNo Then
> Target.Value = vbNullString
> Else
> UserForm7.Show
> End If
> Application.EnableEvents = True
> End If
> End If
>
> When another function is added to the same Worksheet_Change code, the
> second
> one (below) doesn't work.
>
> However, if the first one is removed, it works fine:
>
> ' when date entered in "K", checks "H"
> Dim Res4 As VbMsgBoxResult
> Const Myrange3 = "K4:K4000"
> If Not Intersect(Target, Me.Range("K4:K4000")) Is Nothing Then
> Exit Sub
> End If
> If IsDate(Target) And Target.Offset(, -3) = "" Or
> Target.Offset(, -3)
> = "N" Then
> Application.EnableEvents = False
> Res4 = MsgBox("Cannot issue claim without payment!")
> Target.ClearContents
> Application.EnableEvents = True
> End If
>
>
> The first code above is currently at the end of about 4 pages of other
> code
> in Sheet!1 all of which works ok until the second one is added.
> I have three other subs to add but until I can figure out why they don't
> work, when added in, I am stuck.
>
>
> Can I have a second Worksheet_Change event to put these into or can they
> be
> placed in ThisWorkbook or in a module?
> Help!
> Thanks in advance.
> --
> Traa Dy Liooar
>
> Jock



 
Reply With Quote
 
Jock
Guest
Posts: n/a
 
      12th Oct 2009
OK, thanks JLG.
--
Traa Dy Liooar

Jock


"JLGWhiz" wrote:

> Disregard that. Try this:
>
> If Target.Offset(, 3) = "" Or Target.Offset(, 3) = N Then
> If IsDate(Target) Then
> 'Rest of statement
> End If
> End If
>
>
> "Jock" <(E-Mail Removed)> wrote in message
> news:3ED52ECC-F28E-4595-8B2F-(E-Mail Removed)...
> > Hi,
> > The following code works in a Worksheet_Change (ByVal Target As Range)
> > event:
> >
> > ' Displays message box when "C" is selected in H
> > Dim Res3 As VbMsgBoxResult
> > If Not Intersect(Target, Me.Range("H4:H4000")) Is Nothing Then
> > With Target
> > If Target.Value = "C" Then
> > If Target.Offset(, -1) = "" Then
> > Application.EnableEvents = False
> > Res3 = MsgBox("No account has been selected!", vbOKOnly, "Charging of
> > accounts")
> > Target.Value = vbNullString
> > Else
> > Res3 = MsgBox("Is this item to be charged to an account?",
> > vbYesNo,
> > "Charging of accounts")
> > If Res3 = vbNo Then
> > Target.Value = vbNullString
> > Else
> > UserForm7.Show
> > End If
> > Application.EnableEvents = True
> > End If
> > End If
> >
> > When another function is added to the same Worksheet_Change code, the
> > second
> > one (below) doesn't work.
> >
> > However, if the first one is removed, it works fine:
> >
> > ' when date entered in "K", checks "H"
> > Dim Res4 As VbMsgBoxResult
> > Const Myrange3 = "K4:K4000"
> > If Not Intersect(Target, Me.Range("K4:K4000")) Is Nothing Then
> > Exit Sub
> > End If
> > If IsDate(Target) And Target.Offset(, -3) = "" Or
> > Target.Offset(, -3)
> > = "N" Then
> > Application.EnableEvents = False
> > Res4 = MsgBox("Cannot issue claim without payment!")
> > Target.ClearContents
> > Application.EnableEvents = True
> > End If
> >
> >
> > The first code above is currently at the end of about 4 pages of other
> > code
> > in Sheet!1 all of which works ok until the second one is added.
> > I have three other subs to add but until I can figure out why they don't
> > work, when added in, I am stuck.
> >
> >
> > Can I have a second Worksheet_Change event to put these into or can they
> > be
> > placed in ThisWorkbook or in a module?
> > Help!
> > Thanks in advance.
> > --
> > Traa Dy Liooar
> >
> > Jock

>
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      12th Oct 2009
Typo alert...

Put that "N" in double quotes.

JLGWhiz wrote:
>
> Disregard that. Try this:
>
> If Target.Offset(, 3) = "" Or Target.Offset(, 3) = N Then
> If IsDate(Target) Then
> 'Rest of statement
> End If
> End If
>
> "Jock" <(E-Mail Removed)> wrote in message
> news:3ED52ECC-F28E-4595-8B2F-(E-Mail Removed)...
> > Hi,
> > The following code works in a Worksheet_Change (ByVal Target As Range)
> > event:
> >
> > ' Displays message box when "C" is selected in H
> > Dim Res3 As VbMsgBoxResult
> > If Not Intersect(Target, Me.Range("H4:H4000")) Is Nothing Then
> > With Target
> > If Target.Value = "C" Then
> > If Target.Offset(, -1) = "" Then
> > Application.EnableEvents = False
> > Res3 = MsgBox("No account has been selected!", vbOKOnly, "Charging of
> > accounts")
> > Target.Value = vbNullString
> > Else
> > Res3 = MsgBox("Is this item to be charged to an account?",
> > vbYesNo,
> > "Charging of accounts")
> > If Res3 = vbNo Then
> > Target.Value = vbNullString
> > Else
> > UserForm7.Show
> > End If
> > Application.EnableEvents = True
> > End If
> > End If
> >
> > When another function is added to the same Worksheet_Change code, the
> > second
> > one (below) doesn't work.
> >
> > However, if the first one is removed, it works fine:
> >
> > ' when date entered in "K", checks "H"
> > Dim Res4 As VbMsgBoxResult
> > Const Myrange3 = "K4:K4000"
> > If Not Intersect(Target, Me.Range("K4:K4000")) Is Nothing Then
> > Exit Sub
> > End If
> > If IsDate(Target) And Target.Offset(, -3) = "" Or
> > Target.Offset(, -3)
> > = "N" Then
> > Application.EnableEvents = False
> > Res4 = MsgBox("Cannot issue claim without payment!")
> > Target.ClearContents
> > Application.EnableEvents = True
> > End If
> >
> >
> > The first code above is currently at the end of about 4 pages of other
> > code
> > in Sheet!1 all of which works ok until the second one is added.
> > I have three other subs to add but until I can figure out why they don't
> > work, when added in, I am stuck.
> >
> >
> > Can I have a second Worksheet_Change event to put these into or can they
> > be
> > placed in ThisWorkbook or in a module?
> > Help!
> > Thanks in advance.
> > --
> > Traa Dy Liooar
> >
> > Jock


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
conflict with code =?Utf-8?B?Q3VydA==?= Microsoft Excel Programming 7 17th Mar 2007 12:25 PM
Code 12 - IRQ conflict jh Windows XP Help 0 8th Jun 2006 07:27 PM
I/O conflict ( code 12 ) =?Utf-8?B?c2hha2VyMjU=?= Windows XP Configuration 2 19th Feb 2005 03:45 AM
Resource conflict (Code 12) =?Utf-8?B?UGxhbmc=?= Windows XP General 0 6th Jun 2004 03:01 PM
Code 22 - LPT2 Name Conflict Fortney, James T Microsoft Windows 2000 1 30th Nov 2003 03:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:03 AM.