ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro Looping Problem (https://www.excelbanter.com/excel-programming/403537-macro-looping-problem.html)

[email protected]

Macro Looping Problem
 
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

Charles Chickering

Macro Looping Problem
 
Please post the code you have so far.
--
Charles Chickering

"A good example is twice the value of good advice."


" 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


XP

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



All times are GMT +1. The time now is 11:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com