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

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default 2 Macros in VBA???

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" skrev i meddelelsen
...
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default 2 Macros in VBA???

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" skrev i meddelelsen
...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default 2 Macros in VBA???

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" skrev i meddelelsen
...
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" skrev i
meddelelsen
...
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
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
Macros in Personal.xls that would create two toolbars and buttonswith assigned macros Brian Day Excel Programming 1 March 29th 07 11:20 PM
choose default macros Not Enabled / Macros Enable Setting BEEJAY Excel Programming 2 June 30th 06 01:07 PM
weird saving of a document with macros resulting with macros being transfered to the copy alfonso gonzales Excel Programming 0 December 12th 04 09:19 PM
convert lotus 123w macros to excel macros rpiescik Excel Programming 1 September 18th 04 01:35 PM
Macros not appearing in the Tools Macro Macros list hglamy[_2_] Excel Programming 5 October 24th 03 09:10 AM


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