PC Review


Reply
Thread Tools Rate Thread

2 Macros in VBA???

 
 
Thomas Price
Guest
Posts: n/a
 
      17th Apr 2008
I have these two macros in VBA and they will not work. If I put them in
sepratly they will work but when I put them in together they will not. Can
you help me fix this so I can get them both to work??? Thanks in advance for
your time!

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Application.Intersect(Range("j:k", "y:y"), Target) Is Nothing Then
On Error GoTo ErrHandler
Application.EnableEvents = False
Target.Formula = UCase(Target.Formula)
End If
ErrHandler:
Application.EnableEvents = True
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Range("W5"), Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
If Target.Value = 0 Then
Exit Sub
End If
If Target.Value >= 50000 Then
Range("S5").Value = "HEAVY TRUCK"
End If
If Target.Value < 50000 Then
Range("S5").Value = "LT DUTY TRUCK"
End If
Application.EnableEvents = True
End Sub
 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      17th Apr 2008
Hi

You can only have one "Worksheet_Change" event macro in a worksheet.
Here's how you can do it; put the event code in the codesheet for the
worksheet, and Macro1 & Macro2 in a normal Module.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Call Macro1(Target)
Call Macro2(Target)
End Sub

Sub Macro1(Target)
If Not Application.Intersect(Range("j:k", "y:y"), Target) Is Nothing Then
On Error GoTo ErrHandler
Application.EnableEvents = False
Target.Formula = UCase(Target.Formula)
End If
ErrHandler:
Application.EnableEvents = True
End Sub

Sub Macro2(Target)
If Intersect(Range("W5"), Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
If Target.Value = 0 Then
Exit Sub
End If
If Target.Value >= 50000 Then
Range("S5").Value = "HEAVY TRUCK"
End If
If Target.Value < 50000 Then
Range("S5").Value = "LT DUTY TRUCK"
End If
Application.EnableEvents = True
End Sub

Best regards,
Per

"Thomas Price" <(E-Mail Removed)> skrev i meddelelsen
news:7B4E1107-5E8D-45AE-B1A9-(E-Mail Removed)...
>I have these two macros in VBA and they will not work. If I put them in
> sepratly they will work but when I put them in together they will not.
> Can
> you help me fix this so I can get them both to work??? Thanks in advance
> for
> your time!
>
> Private Sub ByVal Target As Excel.Range)
> If Not Application.Intersect(Range("j:k", "y:y"), Target) Is Nothing Then
> On Error GoTo ErrHandler
> Application.EnableEvents = False
> Target.Formula = UCase(Target.Formula)
> End If
> ErrHandler:
> Application.EnableEvents = True
> End Sub
>
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> If Intersect(Range("W5"), Target) Is Nothing Then Exit Sub
> Application.EnableEvents = False
> If Target.Value = 0 Then
> Exit Sub
> End If
> If Target.Value >= 50000 Then
> Range("S5").Value = "HEAVY TRUCK"
> End If
> If Target.Value < 50000 Then
> Range("S5").Value = "LT DUTY TRUCK"
> End If
> Application.EnableEvents = True
> End Sub


 
Reply With Quote
 
Thomas Price
Guest
Posts: n/a
 
      17th Apr 2008
Per,
Thank you. It worked one time and then stopped working. Do you know
why that is? Thanks!

"Per Jessen" wrote:

> Hi
>
> You can only have one "Worksheet_Change" event macro in a worksheet.
> Here's how you can do it; put the event code in the codesheet for the
> worksheet, and Macro1 & Macro2 in a normal Module.
>
> Private Sub Worksheet_Change(ByVal Target As Excel.Range)
> Call Macro1(Target)
> Call Macro2(Target)
> End Sub
>
> Sub Macro1(Target)
> If Not Application.Intersect(Range("j:k", "y:y"), Target) Is Nothing Then
> On Error GoTo ErrHandler
> Application.EnableEvents = False
> Target.Formula = UCase(Target.Formula)
> End If
> ErrHandler:
> Application.EnableEvents = True
> End Sub
>
> Sub Macro2(Target)
> If Intersect(Range("W5"), Target) Is Nothing Then Exit Sub
> Application.EnableEvents = False
> If Target.Value = 0 Then
> Exit Sub
> End If
> If Target.Value >= 50000 Then
> Range("S5").Value = "HEAVY TRUCK"
> End If
> If Target.Value < 50000 Then
> Range("S5").Value = "LT DUTY TRUCK"
> End If
> Application.EnableEvents = True
> End Sub
>
> Best regards,
> Per
>
> "Thomas Price" <(E-Mail Removed)> skrev i meddelelsen
> news:7B4E1107-5E8D-45AE-B1A9-(E-Mail Removed)...
> >I have these two macros in VBA and they will not work. If I put them in
> > sepratly they will work but when I put them in together they will not.
> > Can
> > you help me fix this so I can get them both to work??? Thanks in advance
> > for
> > your time!
> >
> > Private Sub ByVal Target As Excel.Range)
> > If Not Application.Intersect(Range("j:k", "y:y"), Target) Is Nothing Then
> > On Error GoTo ErrHandler
> > Application.EnableEvents = False
> > Target.Formula = UCase(Target.Formula)
> > End If
> > ErrHandler:
> > Application.EnableEvents = True
> > End Sub
> >
> >
> > Private Sub Worksheet_Change(ByVal Target As Range)
> > If Intersect(Range("W5"), Target) Is Nothing Then Exit Sub
> > Application.EnableEvents = False
> > If Target.Value = 0 Then
> > Exit Sub
> > End If
> > If Target.Value >= 50000 Then
> > Range("S5").Value = "HEAVY TRUCK"
> > End If
> > If Target.Value < 50000 Then
> > Range("S5").Value = "LT DUTY TRUCK"
> > End If
> > Application.EnableEvents = True
> > End Sub

>
>

 
Reply With Quote
 
Per Jessen
Guest
Posts: n/a
 
      17th Apr 2008
The VBA editor must be in break mode for some reason.

Close the workbook an reopen it. Now it should work. I don't know why it
happens.

Regards,
Per

"Thomas Price" <(E-Mail Removed)> skrev i meddelelsen
news:7522621E-DD17-41FC-8BDB-(E-Mail Removed)...
> Per,
> Thank you. It worked one time and then stopped working. Do you know
> why that is? Thanks!
>
> "Per Jessen" wrote:
>
>> Hi
>>
>> You can only have one "Worksheet_Change" event macro in a worksheet.
>> Here's how you can do it; put the event code in the codesheet for the
>> worksheet, and Macro1 & Macro2 in a normal Module.
>>
>> Private Sub Worksheet_Change(ByVal Target As Excel.Range)
>> Call Macro1(Target)
>> Call Macro2(Target)
>> End Sub
>>
>> Sub Macro1(Target)
>> If Not Application.Intersect(Range("j:k", "y:y"), Target) Is Nothing Then
>> On Error GoTo ErrHandler
>> Application.EnableEvents = False
>> Target.Formula = UCase(Target.Formula)
>> End If
>> ErrHandler:
>> Application.EnableEvents = True
>> End Sub
>>
>> Sub Macro2(Target)
>> If Intersect(Range("W5"), Target) Is Nothing Then Exit Sub
>> Application.EnableEvents = False
>> If Target.Value = 0 Then
>> Exit Sub
>> End If
>> If Target.Value >= 50000 Then
>> Range("S5").Value = "HEAVY TRUCK"
>> End If
>> If Target.Value < 50000 Then
>> Range("S5").Value = "LT DUTY TRUCK"
>> End If
>> Application.EnableEvents = True
>> End Sub
>>
>> Best regards,
>> Per
>>
>> "Thomas Price" <(E-Mail Removed)> skrev i
>> meddelelsen
>> news:7B4E1107-5E8D-45AE-B1A9-(E-Mail Removed)...
>> >I have these two macros in VBA and they will not work. If I put them in
>> > sepratly they will work but when I put them in together they will not.
>> > Can
>> > you help me fix this so I can get them both to work??? Thanks in
>> > advance
>> > for
>> > your time!
>> >
>> > Private Sub ByVal Target As Excel.Range)
>> > If Not Application.Intersect(Range("j:k", "y:y"), Target) Is Nothing
>> > Then
>> > On Error GoTo ErrHandler
>> > Application.EnableEvents = False
>> > Target.Formula = UCase(Target.Formula)
>> > End If
>> > ErrHandler:
>> > Application.EnableEvents = True
>> > End Sub
>> >
>> >
>> > Private Sub Worksheet_Change(ByVal Target As Range)
>> > If Intersect(Range("W5"), Target) Is Nothing Then Exit Sub
>> > Application.EnableEvents = False
>> > If Target.Value = 0 Then
>> > Exit Sub
>> > End If
>> > If Target.Value >= 50000 Then
>> > Range("S5").Value = "HEAVY TRUCK"
>> > End If
>> > If Target.Value < 50000 Then
>> > Range("S5").Value = "LT DUTY TRUCK"
>> > End If
>> > Application.EnableEvents = True
>> > End Sub

>>
>>


 
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
Macros in Personal.xls that would create two toolbars and buttonswith assigned macros =?Utf-8?B?SmF5?= Microsoft Excel Programming 1 30th Mar 2007 12:02 AM
choose default macros Not Enabled / Macros Enable Setting =?Utf-8?B?QkVFSkFZ?= Microsoft Excel Programming 2 30th Jun 2006 01:07 PM
weird saving of a document with macros resulting with macros being transfered to the copy alfonso gonzales Microsoft Excel Programming 0 12th Dec 2004 09:19 PM
Removing Excel message to enable macros or disable macros =?Utf-8?B?Ym1pbGxlcjI2Mw==?= Microsoft Excel Misc 2 13th Oct 2004 02:39 PM
Re: The macros in this project are disabled. Please refer to the online help or documentation of the host application to determine how to enable macros. Sue Mosher [MVP-Outlook] Microsoft Outlook Installation 0 17th Feb 2004 05:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:42 PM.