Option Explicit
Sub SELECIONARINTERVALOR()
Application.ScreenUpdating = False
Dim LINHA As Long
For LINHA = 3 To Range("B" & Rows.Count).End(xlUp).Row + 3
If Plan1.Range("B" & LINHA).Value = "" And Plan1.Range("B" & LINHA + 1).Value = "" Then
Plan1.Range("B" & LINHA - 1).Select
Selection.End(xlUp).Select
Dim LINHAINICIAL As Long
LINHAINICIAL = Selection.Row
Plan1.Range("B" & LINHA - 1).Select
Range(Selection, Selection.End(xlUp)).Select
Plan1.Range(Selection, Selection.End(xlToRight)).Select
Dim INTERVALO As String
INTERVALO = Selection.Address
ActiveWorkbook.Worksheets("Plan1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Plan1").Sort.SortFields.Add Key:=Range("Q" & LINHAINICIAL & ":Q" & LINHA - 1), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Plan1").Sort
.SetRange Range(INTERVALO)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
LINHA = LINHA + 2
End If
Next LINHA
Application.ScreenUpdating = True
End Sub
Postado : 17/04/2018 9:56 am