![]() |
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 |
All times are GMT +1. The time now is 01:32 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com