本帖最后由 乐乐2006201505 于 2018-8-6 22:41 编辑
Sub Macro1()
Dim arr, brr(), i&
arr = Sheets(1).Range("a1").CurrentRegion
ReDim brr(1 To UBound(arr) * 3 - 3, 1 To 3)
For i = 2 To UBound(arr)
brr(i - 1, 1) = arr(1, 2)
brr(i - 1, 2) = arr(i, 1)
brr(i - 1, 3) = arr(i, 2)
brr(i - 2 + 16, 1) = arr(1, 3)
brr(i - 2 + 16, 2) = arr(i, 1)
brr(i - 2 + 16, 3) = arr(i, 3)
brr(i - 3 + 32, 1) = arr(1, 4)
brr(i - 3 + 32, 2) = arr(i, 1)
brr(i - 3 + 32, 3) = arr(i, 4)
Next
With Sheets("sheet1")
.UsedRange.Offset(1).ClearContents
.Range("C2:C" & UBound(arr)).NumberFormatLocal = "0.0_ "
.Range("a2").Resize(UBound(brr), UBound(brr, 2)) = brr
End With
End Sub自己的办法太笨,本来有和版主一样的思路,不过功力太浅,无法达到。下面代码是在版主代码基础上修改的,一起上传,方便自己以后使用。
Sub gj23w98()
Dim brr
arr = Sheet1.[a1].CurrentRegion
ReDim brr(1 To UBound(arr) * 3 - 3, 1 To 3)
For j = 2 To UBound(arr, 2)
For i = 2 To UBound(arr)
If Len(arr(i, j)) Then
m = m + 1
brr(m, 1) = arr(1, j)
brr(m, 2) = arr(i, 1)
brr(m, 3) = arr(i, j)
End If
Next
Next
With Sheets("sheet1")
.UsedRange.Offset(0).ClearContents
.Range("b1") = arr(1, 1)
.Range("C2:C" & UBound(arr) * 3 - 2).NumberFormatLocal = "0.0_ "
If m Then .Range("a2").Resize(UBound(brr), UBound(brr, 2)) = brr
End With
End Sub
|