Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Ben Dummar
 
Posts: n/a
Default How to run Multiple Macro's in Worksheet?

Hi,

When I use the following macro's one at a time in the worksheet they work
great. What do I need to do to be able to run both of them in the same
worksheet at the same time?

Thanks,
Ben

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'to install -- right-click on the sheettab of the corresponding
' sheet and choose 'view code'. Paste the following procedure
' in the module.
If Target.Column < 2 Then Exit Sub
If Target.Row = 1 Then Exit Sub
On Error GoTo ErrHandler
Application.EnableEvents = False
Dim R As Long
R = Target.Row
Target.Offset(0, 2).Value = Date

ErrHandler:
Application.EnableEvents = True
End Sub

Sub Worksheet_Change(ByVal Target As Excel.Range)
If Intersect(Range("l2:l15"), Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
Range("l2:m15").Sort Key1:=Range("l2")
Application.EnableEvents = True
End Sub




  #2   Report Post  
Posted to microsoft.public.excel.misc
Norman Jones
 
Posts: n/a
Default How to run Multiple Macro's in Worksheet?

Hi Ben,

When I use the following macro's one at a time in the worksheet they work
great. What do I need to do to be able to run both of them in the same
worksheet at the same time?


It is only possible to have one Worksheet_Change procedure in a given sheet
module. Therefore, you need to combine your two procedures.

Try replacing the existing code with:

'=============
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim R As Long
R = Target.Row

If Target.Column < 2 Then Exit Sub
If Target.Row = 1 Then Exit Sub

On Error GoTo ErrHandler
Application.EnableEvents = False
Target.Offset(0, 2).Value = Date

If Not Intersect(Range("l2:l15"), Target) Is Nothing Then
Range("l2:m15").Sort Key1:=Range("l2")
End If

ErrHandler:
Application.EnableEvents = True
End Sub
'<<=============


---
Regards,
Norman


  #3   Report Post  
Posted to microsoft.public.excel.misc
Ben Dummar
 
Posts: n/a
Default How to run Multiple Macro's in Worksheet?

Norman,

Thanks for the quick response. Thanks for the info on combining. The first
half of the change_event works but the second part(the autosort) doesn't work
when combined. It is like it doesn't check to see if the second event
occured.

"Norman Jones" wrote:

Hi Ben,

When I use the following macro's one at a time in the worksheet they work
great. What do I need to do to be able to run both of them in the same
worksheet at the same time?


It is only possible to have one Worksheet_Change procedure in a given sheet
module. Therefore, you need to combine your two procedures.

Try replacing the existing code with:

'=============
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim R As Long
R = Target.Row

If Target.Column < 2 Then Exit Sub
If Target.Row = 1 Then Exit Sub

On Error GoTo ErrHandler
Application.EnableEvents = False
Target.Offset(0, 2).Value = Date

If Not Intersect(Range("l2:l15"), Target) Is Nothing Then
Range("l2:m15").Sort Key1:=Range("l2")
End If

ErrHandler:
Application.EnableEvents = True
End Sub
'<<=============


---
Regards,
Norman



  #4   Report Post  
Posted to microsoft.public.excel.misc
Norman Jones
 
Posts: n/a
Default How to run Multiple Macro's in Worksheet?

Hi Ben,

Try the following version:

'=============
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim R As Long
R = Target.Row

If Not Intersect(Range("l2:l15"), Target) Is Nothing Then
Range("l2:m15").Sort Key1:=Range("l2")
End If

If Target.Column < 2 Then Exit Sub
If Target.Row = 1 Then Exit Sub

On Error GoTo ErrHandler
Application.EnableEvents = False
Target.Offset(0, 2).Value = Date

If Not Intersect(Range("l2:l15"), Target) Is Nothing Then
Range("l2:m15").Sort Key1:=Range("l2")
End If

ErrHandler:
Application.EnableEvents = True
End Sub
'<<=============

--
---
Regards,
Norman



"Ben Dummar" wrote in message
...
Norman,

Thanks for the quick response. Thanks for the info on combining. The
first
half of the change_event works but the second part(the autosort) doesn't
work
when combined. It is like it doesn't check to see if the second event
occured.

"Norman Jones" wrote:

Hi Ben,

When I use the following macro's one at a time in the worksheet they
work
great. What do I need to do to be able to run both of them in the same
worksheet at the same time?


It is only possible to have one Worksheet_Change procedure in a given
sheet
module. Therefore, you need to combine your two procedures.

Try replacing the existing code with:

'=============
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim R As Long
R = Target.Row

If Target.Column < 2 Then Exit Sub
If Target.Row = 1 Then Exit Sub

On Error GoTo ErrHandler
Application.EnableEvents = False
Target.Offset(0, 2).Value = Date

If Not Intersect(Range("l2:l15"), Target) Is Nothing Then
Range("l2:m15").Sort Key1:=Range("l2")
End If

ErrHandler:
Application.EnableEvents = True
End Sub
'<<=============


---
Regards,
Norman





  #5   Report Post  
Posted to microsoft.public.excel.misc
Norman Jones
 
Posts: n/a
Default How to run Multiple Macro's in Worksheet?

Hi Ben,

Try the following version:


Should read:

'=============
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim R As Long
R = Target.Row

On Error GoTo ErrHandler
Application.EnableEvents = False

If Not Intersect(Range("I2:I15"), Target) Is Nothing Then
Range("I2:M15").Sort Key1:=Range("I2") '<<== CHECK RANGE
End If

If Target.Column < 2 Then Exit Sub
If Target.Row = 1 Then Exit Sub

Target.Offset(0, 2).Value = Date

ErrHandler:
Application.EnableEvents = True
End Sub
'<<=============


---
Regards,
Norman




  #6   Report Post  
Posted to microsoft.public.excel.misc
Ben Dummar
 
Posts: n/a
Default How to run Multiple Macro's in Worksheet?

Normon,

Thanks!

I got it to work by changing "Application.EnableEvents = False " to
"Application.EnableEvents = True".

Will or is that causing some negative side affect that I am currently not
seeing?

"Norman Jones" wrote:

Hi Ben,

Try the following version:


Should read:

'=============
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim R As Long
R = Target.Row

On Error GoTo ErrHandler
Application.EnableEvents = False

If Not Intersect(Range("I2:I15"), Target) Is Nothing Then
Range("I2:M15").Sort Key1:=Range("I2") '<<== CHECK RANGE
End If

If Target.Column < 2 Then Exit Sub
If Target.Row = 1 Then Exit Sub

Target.Offset(0, 2).Value = Date

ErrHandler:
Application.EnableEvents = True
End Sub
'<<=============


---
Regards,
Norman



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
Run macros on protected worksheet paul Excel Worksheet Functions 0 February 4th 06 11:53 AM
toolbar macros that dont change when worksheet is renamed marlin40 New Users to Excel 1 November 21st 05 07:25 PM
Using worksheet functions in macros in Excel2000 clippan Excel Worksheet Functions 1 November 17th 05 11:53 PM
separate worksheet into multiple worksheets by grouping BPM001 Excel Worksheet Functions 1 November 5th 05 02:48 AM
Reference the worksheet from a multiple worksheet range function ( DBickel Excel Worksheet Functions 1 May 28th 05 03:49 AM


All times are GMT +1. The time now is 06:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"