Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Conditional Sum Argument results do not equal cell results Excel | Excel Worksheet Functions | |||
Wanting to write results to array instead of sheet, results overwriting.... | Excel Programming | |||
Solver code does not save results to sheet - What am I missing?! | Excel Programming | |||
How can I list the results of my macro without overwritng previous results? | Excel Programming | |||
Stepping through code gives different results than running it! | Excel Programming |