SOLVED

Worksheets in alphabetical order with the help of VBA code

Iron Contributor

Hello Everyone,

 

Wish you a Merry Christmas.

 

I have written VBA code to import TEXT file to EXCEL file. And it successfully import.

 

CODE :

Screenshot (5760).png

 

Result :

Screenshot (5761).png

But how to Worksheets in alphabetical order with the help of VBA? What should add in VBA?

 

Here is a attached file...

2 Replies
best response confirmed by VI_Migration (Silver Contributor)
Solution

@Excel 

Here is a macro to sort sheets:

Sub SortSheets()
    Dim i As Long
    Dim j As Long
    For i = 1 To Worksheets.Count - 1
        For j = i + 1 To Worksheets.Count
            If Worksheets(i).Name > Worksheets(j).Name Then
                Worksheets(j).Move Before:=Worksheets(i)
            End If
        Next j
    Next i
End Sub

You can call it at the end of ImprtTextFile, if desired.

It worked. Thank you so much sir.
1 best response

Accepted Solutions
best response confirmed by VI_Migration (Silver Contributor)
Solution

@Excel 

Here is a macro to sort sheets:

Sub SortSheets()
    Dim i As Long
    Dim j As Long
    For i = 1 To Worksheets.Count - 1
        For j = i + 1 To Worksheets.Count
            If Worksheets(i).Name > Worksheets(j).Name Then
                Worksheets(j).Move Before:=Worksheets(i)
            End If
        Next j
    Next i
End Sub

You can call it at the end of ImprtTextFile, if desired.

View solution in original post