你自己发到了基础区 还说没人帮助你
- Sub Transform()
- Dim Wb As Workbook
- Dim Sht As Worksheet
- Dim arr, ar()
- Set Wb = Application.ThisWorkbook
- Set Sht = Wb.Worksheets(1)
-
- With Sht
- Set Rng = .Range("A1").CurrentRegion
- arr = Rng.Value
- n = 0
- For j = 5 To UBound(arr, 2)
- For i = 2 To UBound(arr, 1) Step 5
- n = n + 1
- ReDim Preserve ar(1 To 9, 1 To n)
- ar(1, n) = arr(1, j)
- ar(2, n) = arr(i, 1)
- ar(3, n) = arr(i, 2)
- ar(4, n) = arr(i, 3)
- ''''
- ar(5, n) = arr(i, j)
- ar(6, n) = arr(i + 1, j)
- ar(7, n) = arr(i + 2, j)
- ar(8, n) = arr(i + 3, j)
- ar(9, n) = arr(i + 4, j)
- Next i
- Next j
-
- .Range("Q:Y").ClearContents
- Set Rng = .Range("Q2")
- Set Rng = Rng.Resize(UBound(ar, 2), UBound(ar, 1))
- Rng.Value = Application.WorksheetFunction.Transpose(ar)
-
- End With
-
- Set Wb = Nothing
- Set Sht = Nothing
- Set Rng = Nothing
-
-
- End Sub
复制代码 |