|
Sub 数据正反转置()
Dim arr, brr, crr
Sheet1.Activate
With Sheet1
x = .UsedRange.Rows.Count
y = .Range("IV1").End(xlToLeft).Column '最大列数
arr = .Range(Cells(1, 1), Cells(x, y))
End With
ReDim brr(1 To UBound(arr), 1 To UBound(arr))
ReDim crr(1 To UBound(arr), 1 To UBound(arr))
For J = 1 To UBound(arr, 2)
LH = 0: LHh = 0
For I = 1 To UBound(arr)
If Trim(arr(I, J)) <> "" Then
LH = LH + 1
brr(J, LH) = arr(I, J)
End If
Next I
For I = UBound(arr) To 1 Step -1
If Trim(arr(I, J)) <> "" Then
LHh = LHh + 1
crr(J, LHh) = arr(I, J)
End If
Next I
Next J
Sheet2.Activate
Cells.Delete Shift:=xlUp
Sheet2.Range("A1").Resize(UBound(arr, 2), UBound(arr)) = brr
l = Sheet2.Range("A65536").End(xlUp).Row
Sheet2.Range("A" & l + 1).Resize(UBound(arr, 2), UBound(arr)) = crr
MsgBox "ok!"
End Sub |
评分
-
1
查看全部评分
-
|