Excel 如何用VBA实现表数据格式转换
展开全部
这个实现起来不难,主要是程序的控制,试试下面的代码:
Sub zz()
Dim ar, a(), b(), n&, t
a = Array(3, 7, 11): b = Array(6, 10, 15)
ar = Sheets(1).[a1].CurrentRegion.Value
ReDim c(1 To (UBound(ar) - 1) * (UBound(b) + 2), 1 To 1)
For i = 2 To UBound(ar)
n = n + 1
c(n, 1) = ar(i, 1) & " " & ar(i, 2)
For j = 0 To UBound(a)
n = n + 1
For jj = a(j) To b(j)
c(n, 1) = c(n, 1) & Trim(ar(1, jj)) & "=" & ar(i, jj) & ","
Next
Next
t = Split(c(n, 1), ",")
c(n, 1) = Join(Array(t(0), t(1), t(2), t(4), t(3)), ",")
Next
Workbooks.Add 1
[a1].Resize(n) = c
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |