二维数组旋转
z
Sub 宏1()
'逆时针旋转90度
' 宏1 宏
Dim CountNum As Integer
Dim Rng As Range
Dim arr(), temArr()
Dim rowStar As Integer, rowEnd As Integer
Dim maxInt As Integer
Dim colStar As Integer, colEnd As Integer
Dim temStr As String
Set Rng = Worksheets("Sheet1").UsedRange
arr = WorksheetFunction.Transpose(Rng)
arr = WorksheetFunction.Transpose(arr)
If UBound(arr) > UBound(arr, 2) Then
maxInt = UBound(arr)
Else
maxInt = UBound(arr, 2)
End If
ReDim temArr(1 To maxInt + 1, 1 To maxInt + 1)
For i = LBound(arr) To UBound(arr)
For j = LBound(arr, 2) To UBound(arr, 2)
CountNum = CountNum + 1
'-90
' temArr(Abs(UBound(arr, 1) - UBound(arr, 2) - j), i) = arr(i, j)
'-180
' temArr(Abs(UBound(arr, 1) - i + 1), UBound(arr, 2) - j + 1) = arr(i, j)
'-270
temArr(j, Abs(UBound(arr, 1) - i) + 1) = arr(i, j)
Next
Next
Worksheets("Sheet2").Range("a1").Resize(UBound(temArr), UBound(temArr, 2)) = temArr
End Sub