#1   Report Post  
Posted to microsoft.public.excel.misc
nc nc is offline
external usenet poster
 
Posts: 119
Default Macro

What statement must be included in a macro to make it run as one, but part
one must be completed before part two starts?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,624
Default Macro

Hard to say without knowing what's involved in your part one and part
two and what you mean by "completed".

Simplest solution is to use a single macro and put the part two stuff
after the part one stuff.

You could also run the second part as a separate macro:

Public Sub PartOne()
'Do all part one stuff
PartTwo
End Sub

Public Sub PartTwo()
'Do part two stuff stuff
End Sub




In article ,
nc wrote:

What statement must be included in a macro to make it run as one, but part
one must be completed before part two starts?

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Macro

The first part will usually complete before the second part runs, but if this
is not occuring, try inserting a DoEvents between the two parts
--
Gary''s Student - gsnu200717


"nc" wrote:

What statement must be included in a macro to make it run as one, but part
one must be completed before part two starts?

  #4   Report Post  
Posted to microsoft.public.excel.misc
nc nc is offline
external usenet poster
 
Posts: 119
Default Macro

Hi
Thanks for your reply. I am trying to run the following macro, only the
first sort process works when the first worksheet change takes place, the
second sort process only works for subsequent changes.


Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False

'First sort process

Range("Data1").Sort Key1:=Range("P18"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=M, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

'Second sort depedent on first sort process

rs = Application.WorksheetFunction.CountA(Range("B:B")) + 15
cs = Application.WorksheetFunction.CountA(Range("15:15" )) + 1

nb = Application.WorksheetFunction.CountBlank(Range("P1 8:P" & rs))
nf = Application.WorksheetFunction.CountIf(Range("P18:P " & rs), "FIN")
sr = rs + 1 - nb - nf
Range(Cells(sr, 1), Cells(rs, cs)).Select
Selection.Sort Key1:=Cells(sr, cs - 1), Order1:=xlAscending,
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Application.Calculate

ActiveWorkbook.RefreshAll

Application.EnableEvents = True

End Sub



"JE McGimpsey" wrote:

Hard to say without knowing what's involved in your part one and part
two and what you mean by "completed".

Simplest solution is to use a single macro and put the part two stuff
after the part one stuff.

You could also run the second part as a separate macro:

Public Sub PartOne()
'Do all part one stuff
PartTwo
End Sub

Public Sub PartTwo()
'Do part two stuff stuff
End Sub




In article ,
nc wrote:

What statement must be included in a macro to make it run as one, but part
one must be completed before part two starts?


  #5   Report Post  
Posted to microsoft.public.excel.misc
nc nc is offline
external usenet poster
 
Posts: 119
Default Macro

Hi Gary

Thank for your suggestion. I added DoEvents between the two parts, but it
did not work. I am going to try JE McGimpsey suggestion of splitting the two
parts into two seperate macros. He wanted to have a look at the full macro I
have included it in my reply to him.

"Gary''s Student" wrote:

The first part will usually complete before the second part runs, but if this
is not occuring, try inserting a DoEvents between the two parts
--
Gary''s Student - gsnu200717


"nc" wrote:

What statement must be included in a macro to make it run as one, but part
one must be completed before part two starts?



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,624
Default Macro

Since you can only have one _Change event macro per sheet, one way
(assuming I understand you correctly):

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Static bAlreadyRunOnce As Boolean

On Error GoTo ErrorHandler
Application.EnableEvents = False

If Not bAlreadyRunOnce Then
Range("Data1")...
bAlreadyRunOnce = True
Else
rs =Application.WorksheetFunction.CountA(...
...
End If
ErrorHandler:
Application.EnableEvents = True
End Sub

In article ,
nc wrote:

Hi
Thanks for your reply. I am trying to run the following macro, only the
first sort process works when the first worksheet change takes place, the
second sort process only works for subsequent changes.


Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False

'First sort process

Range("Data1").Sort Key1:=Range("P18"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=M, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

'Second sort depedent on first sort process

rs = Application.WorksheetFunction.CountA(Range("B:B")) + 15
cs = Application.WorksheetFunction.CountA(Range("15:15" )) + 1

nb = Application.WorksheetFunction.CountBlank(Range("P1 8:P" & rs))
nf = Application.WorksheetFunction.CountIf(Range("P18:P " & rs),
"FIN")
sr = rs + 1 - nb - nf
Range(Cells(sr, 1), Cells(rs, cs)).Select
Selection.Sort Key1:=Cells(sr, cs - 1), Order1:=xlAscending,
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Application.Calculate

ActiveWorkbook.RefreshAll

Application.EnableEvents = True

End Sub



"JE McGimpsey" wrote:

Hard to say without knowing what's involved in your part one and part
two and what you mean by "completed".

Simplest solution is to use a single macro and put the part two stuff
after the part one stuff.

You could also run the second part as a separate macro:

Public Sub PartOne()
'Do all part one stuff
PartTwo
End Sub

Public Sub PartTwo()
'Do part two stuff stuff
End Sub




In article ,
nc wrote:

What statement must be included in a macro to make it run as one, but
part
one must be completed before part two starts?


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
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 1 February 5th 07 09:31 PM
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 3 February 5th 07 08:22 PM
using a cell value to control a counter inside a macro and displaying macro value ocset Excel Worksheet Functions 1 September 10th 06 05:32 AM
Macro needed to Paste Values and prevent Macro operation thunderfoot Excel Discussion (Misc queries) 1 June 11th 05 12:44 AM
Macro needed to Paste Values and prevent Macro operation thunderfoot Excel Discussion (Misc queries) 0 June 10th 05 03:38 PM


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