现在我们想做如下操作:
想把表1的数据转化为表2的数据,那么我们只需要如下这段代码即可解决需求
Sub 转置()Dim i%, arrarr = Application.InputBox("选择区域", Type:=8)t1 = UBound(arr)t2 = UBound(arr, 2)ReDim brr(1 To t1 * t2, 1 To 3)For i = 2 To t1 m = 1 For k = i To i + t2 - 2 n = n + 1 m = m + 1 brr(n, 1) = arr(i, 1) brr(n, 2) = arr(1, m) brr(n, 3) = arr(i, m) Next kNext itishi = Application.InputBox("选择存放起始单元格", Type:=8).Address(0, 0)Range(tishi) = arr(1, 1)Range(tishi).Offset(1, 0).Resize(UBound(brr), 3) = brrEnd Sub