Aaah, então nem precisa de loop... Só mandar executar na Sheet ativa.
Option Explicit
Sub arrumar()
Dim ws As Worksheet
Dim UltL As Long
'Dim i As Long
Dim j As Long
Application.ScreenUpdating = False
' For i = 1 To ThisWorkbook.Worksheets.Count
Set ws = ThisWorkbook.activesheet
UltL = ws.Cells(Rows.Count, 16).End(xlUp).Row
ws.Activate
ws.Sort.SortFields.Clear
ws.Sort.SortFields.Add Key:=ws.Range("P2:P" & UltL), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ws.Sort.SortFields.Add Key:=ws.Range("M2:M" & UltL), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ws.Sort.SortFields.Add Key:=ws.Range("N2:N" & UltL), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ws.Sort
.SetRange Range("A1:AE" & UltL)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Selection.CurrentRegion.Select
With Selection
For j = 5 To 6
.Borders(j).LineStyle = xlNone
Next j
For j = 7 To 12
.Borders(j).LineStyle = xlContinuous
Next j
End With
Cells.Select
Cells.EntireColumn.AutoFit
ws.Range("A1").Select
' Next i
Set ws = Nothing
Application.ScreenUpdating = True
MsgBox "Processo finalizado com sucesso!" ' & vbNewLine & "Planilhas executadas: " & i
End Sub
Acho que vai funcionar...
Mas pooooode ser que tenha que ajustar algo.
Estou pelo celular.
Qualquer coisa da o grito.
Abraço
Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel
Postado : 11/01/2017 4:44 pm