Views

Histats

Vitrine

VBA Excel - Ordenando Alfabeticamente as Abas - Sort all worksheets on the basis of Sheet names

Blog Office VBA | Blog Excel | Blog Access |
Inline image 1

Quando a nossa aplicação gera novas abas com conteúdo no MS Excel, é importante que ordenemos o resultado. Como?

Sub SortALLSheets()

  'This module will sort all the worksheets present in active workbook.
  Dim iSheet As Long, iBefore As Long

  For iSheet = 1 To ActiveWorkbook.Sheets.count
    Sheets(iSheet).Visible = True

    For iBefore = 1 To iSheet - 1
      If UCase(Sheets(iBefore).Name) > UCase(Sheets(iSheet).Name) Then
        ActiveWorkbook.Sheets(iSheet).Move before:=ActiveWorkbook.Sheets(iBefore)

        Exit For
      End If
    Next iBefore

  Next iSheet

End Sub

Reference:
Tags: VBA, Excel, ordenar, alfabético, sort, worksheets, 



LinkWithinBrazilVBAExcelSpecialist

Related Posts Plugin for WordPress, Blogger...