Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 391
Default Worksheet Sort - but all sheets in array do not exist

2003

Thanks to Chuck Pearson I have the following VBA code:

Sub SortWS3()

Dim SortOrder As Variant
Dim Ndx As Long
SortOrder = Array("CSheet", "ASheet", "BSheet")
For Ndx = UBound(SortOrder) To LBound(SortOrder) Step -1
Worksheets(SortOrder(Ndx)).Move befo=Worksheets(1)
Next Ndx

End Sub

The challenge is that each workbook may not have all of the sheets.

What I need is a way for the array to SKIP the non-existant sheets OR
an alternative approach.

Any thoughts are appreciated

Thanks EagleOne
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default Worksheet Sort - but all sheets in array do not exist

I think maybe the easiest way would be to simply ignore the error created if
you try to move a sheet that doesn't exist, and then do some error cleanup if
it does happen.

On Error Resume Next ' for 'in line' error testing
For Ndx = Ubound(SortOrder) To LBound(SortOrder) Step -1
Worksheets(SortOrder(Ndx).Move befo=Worksheets(1)
If Err < 0 then
Err.clear ' assume sheet didn't exist
End If
Next
On Error GoTo 0 ' no more error trapping.

" wrote:

2003

Thanks to Chuck Pearson I have the following VBA code:

Sub SortWS3()

Dim SortOrder As Variant
Dim Ndx As Long
SortOrder = Array("CSheet", "ASheet", "BSheet")
For Ndx = UBound(SortOrder) To LBound(SortOrder) Step -1
Worksheets(SortOrder(Ndx)).Move befo=Worksheets(1)
Next Ndx

End Sub

The challenge is that each workbook may not have all of the sheets.

What I need is a way for the array to SKIP the non-existant sheets OR
an alternative approach.

Any thoughts are appreciated

Thanks EagleOne

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 391
Default Worksheet Sort - but all sheets in array do not exist

Works great!! Thanks

JLatham wrote:

On Error Resume Next ' for 'in line' error testing
For Ndx = Ubound(SortOrder) To LBound(SortOrder) Step -1
Worksheets(SortOrder(Ndx).Move befo=Worksheets(1)
If Err < 0 then
Err.clear ' assume sheet didn't exist
End If
Next

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
Sort referenced sheets together! Addy Excel Worksheet Functions 3 January 12th 06 02:47 PM
Sort Columns in Protected Worksheet, etc. EDSTAFF Excel Worksheet Functions 0 October 26th 05 12:09 AM
Refrencing another cell in a worksheet that "could" exist KimberlyC Excel Worksheet Functions 1 February 7th 05 07:09 PM
Is it possible to sort a protected worksheet? Phyllis Excel Discussion (Misc queries) 8 January 6th 05 04:45 PM
HELP! How do you--> Lock a set of rows but also link worksheets to FRUSTRATED Excel Discussion (Misc queries) 6 December 29th 04 10:05 PM


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