Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Same code - different results

I have found a macro that I am using in Microsoft Project that uses excel.
It alphabatizes the worksheets. It runs fine the first time. If I run it
again without exiting excel it does not sort the worksheets but does not
produce an error. If I exit excel and run it again I get an error that says
run-time error '1004': Method 'Worksheets of object'_Global' failed. If I
then run it again without exiting Excel it does not work but does not produce
an error. If I exit Excel and run it agian it works fine.

I have pasted the sub below.

Private Sub SortWorksheets()

Dim N As Integer
Dim M As Integer
Dim FirstWSToSort As Integer
Dim LastWSToSort As Integer

FirstWSToSort = 3
LastWSToSort = xlApp.Worksheets.Count

For M = FirstWSToSort To LastWSToSort
For N = M To LastWSToSort
If UCase(Worksheets(N).Name) < UCase(Worksheets(M).Name) Then
Worksheets(N).Move befo=Worksheets(M)
End If
Next N
Next M

End Sub

Thanks,
Scott Hanebutt
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
Conditional Sum Argument results do not equal cell results Excel Randy R Mullins Excel Worksheet Functions 3 August 9th 06 07:16 PM
Wanting to write results to array instead of sheet, results overwriting.... [email protected] Excel Programming 2 October 31st 05 01:47 PM
Solver code does not save results to sheet - What am I missing?! Simon Livings Excel Programming 0 January 16th 04 03:55 PM
How can I list the results of my macro without overwritng previous results? mattip Excel Programming 3 November 28th 03 03:45 AM
Stepping through code gives different results than running it! Simon White Excel Programming 2 November 13th 03 09:44 PM


All times are GMT +1. The time now is 03:16 PM.

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"