Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao frysky,
Oltre agli ottimi suggerimenti di Mauro, credo sia consigliabile evitare, quando possibile, le selezioni di celle. Pertanto, sfruttando i suggerimenti di Mauro, forse prova qualcosa del genere:
'=========>>
Option Explicit
'--------->>
Public Sub ORDINA()
Dim SH As Worksheet
Dim Rng As Range
Dim Res As Variant
Const myCells As String = "A1:D41" '<<=== Modifica
Set SH = ActiveSheet
Set Rng = SH.Range(myCells)
With SH.Sort
With .SortFields
.Clear
.Add Key:=Rng.Columns(1), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
.Add Key:=Rng.Columns(Rng.Columns.Count), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
End With
.SetRange Rng
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
'<<=========
Se il numero di righe o colonne fosse variabile, da un foglio ad un altro e, a patto che l'intervallo da ordinare fosse racchiuso ad ogni lato da una riga o colonna vuota, forse potresti provare invece la seguente versione:
'=========>>
Option Explicit
'--------->>
Public Sub ORDINA()
Dim SH As Worksheet
Dim Rng As Range
Dim Res As Variant
Set SH = ActiveSheet
Set Rng = SH.Range("A1").CurrentRegion
With SH.Sort
With .SortFields
.Clear
.Add Key:=Rng.Columns(1), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
.Add Key:=Rng.Columns(Rng.Columns.Count), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
End With
.SetRange Rng
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
'<<=========
===
Regards,
Norman