Andrea Terzaghi

Suggerimenti su come usare Excel da un utente ad altri utenti

My Links

Categorie Post

Archivio

Blog Stats

Excel

mercoledì 11 gennaio 2006 #

Ordinare i fogli Excel in un file

E' possibile ordinare i fogli Excel all'interno di un file con una piccola macro:

______________________________________________

Sub ordina()
Dim ws As Worksheet
Dim prec As String
Dim corr As String
Dim spostamento As Boolean
Dim primo As Boolean
Dim i As Integer

spostamento = True
While spostamento = True

    primo = True
    spostamento = False
    prec = ""
    corr = ""
    For Each ws In Worksheets
        If primo Then
            corr = LCase(ws.Name)
            primo = False
        Else
            prec = corr
            corr = LCase(ws.Name)
        End If
        If prec <> "" Then
            If corr < prec Then
                spostamento = True
                ws.Move Before:=Sheets(prec)
            End If
        End If
    Next
Wend

End Sub
______________________________________________

La macro utilizza la tecnica BubbleSort che, dato il basso numero di elementi da ordinare (qualche decina al massimo) è assolutamente efficace

Potete scaricare un piccolo file di esempio da:

http://www.terzaghi.it/excel/faq/risposte/24.htm

posted @ 0.58 | Feedback (0)