這個實現起來不難,主要是程式的控制,試試下面的程式碼: 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
這個實現起來不難,主要是程式的控制,試試下面的程式碼: 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