View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
XP XP is offline
external usenet poster
 
Posts: 389
Default Macro Looping Problem

Here is one way:

Right click on the sheet tab of the sheet that should sort the sheets.
Select "View Code" and paste in the following two functions:

Private Sub Worksheet_Activate()
Call SheetSortDOSLogic
End Sub

Public Function SheetSortDOSLogic()
Dim lngX As Integer
Dim lngY As Integer
Dim lngSheetCount As Long
lngSheetCount = ActiveWorkbook.Sheets.Count
For lngX = 1 To lngSheetCount
For lngY = lngX + 1 To lngSheetCount
If Sheets(lngX).Name Sheets(lngY).Name Then
Sheets(lngY).Move Befo=Sheets(lngX)
End If
Next lngY
Next lngX
End Function

To make it run again, you must select a different tab and then reselect the
"sort" sheet tab.

HTH

" wrote:

Help please, I am new to macro and VBA and have a problem,

I neen a macro to run when a worksheet tab is clicked, the macro
peforma a sort on the rest of the tabs the problem is that i need it
to end on that tab and to sort, so when that tab is selected at the
end of the macro the macro runs again and goes into a loop.

Is that a way to run the macro once and stop it?

Thanks