
Sub swaprows()
Dim i As Integer, j As Integer, temp As Integer, arr(), first As Integer, last As Integer
LR = Cells(Rows.Count, "D").End(xlUp).Row
Set Rng = Range("D14:H" & LR)
arr = Rng.Value
last = UBound(arr)
For i = 1 To last / 2
temp1 = arr(last - i + 1, 1)
temp2 = arr(last - i + 1, 2)
arr(last - i + 1, 1) = arr(i, 1)
arr(last - i + 1, 2) = arr(i, 2)
arr(i, 1) = temp1
arr(i, 2) = temp2
Next
Rng.Value = arr
End Sub |
Sub swap_rows()
Dim arr()
LR = Cells(Rows.Count, "D").End(xlUp).Row
Set Rng = Range("D14:H" & LR)
last = Rng.Rows.Count
ReDim arr(last, 5)
For i = 1 To last
For c = 1 To 5
arr(i, c) = Rng(last - i + 1, c)
Next
Next
Rng.Value = arr
End Sub |
'--------------------------------------------------------------------------------------- |
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
Option Base 1
Sub swap_rows()
Dim arr()
LR = Cells(Rows.Count, "D").End(xlUp).Row
Set Rng = Range("D14:H" & LR)
last = Rng.Rows.Count
ReDim arr(last, 5)
For i = 1 To last
For c = 1 To 5
arr(i, c) = Rng(last - i + 1, c)
Next
Next
Rng.Value = arr
End Sub |
Public Sub InvertiRighe()
Dim rng As Range
Dim rRow As Range
Dim aRng As Variant
Dim aInv As Variant
Dim j As Long
Dim k As Long
Dim i As Long
Dim nRows As Long
Dim nCols As Long
On Error GoTo Err_sub
LR = Cells(Rows.Count, "D").End(xlUp).Row
Set Rng = Range("D14:H" & LR)
nRows = rng.Rows.Count
nCols = rng.Columns.Count
If nRows < 2 Then Err.Raise vbObjectError + 513, Description:="Selezionare almeno due righe."
aRng = rng
aInv = aRng
For i = nRows To 1 Step -1
j = j + 1
For k = 1 To nCols
aInv(j, k) = aRng(i, k)
Next k
Next
rng = aInv
rng.Cells(1, 1).Select
Err_sub:
Set rng = Nothing
If Err.Number <> 0 Then
MsgBox Err.Description, vbCritical
Else
MsgBox "operazione terminata", vbInformation
End If
End Sub
|
