Excel VBA - 将多列中的数据重新组织为新行

时间:2016-07-20 15:38:33

标签: excel vba excel-vba

我在Excel中有一些我需要重新组织的数据。这基本上就是我需要的东西:

Sample Data

数据从单元格A1开始("名字"在单元格A1中),我在"网站"之后有其他列。太。我不太了解VBA,所以如果有人可以为此提供完整的解决方案,我将不胜感激。

谢谢!

1 个答案:

答案 0 :(得分:0)

Sub Macro3()
Dim sh As Worksheet
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim m As Integer
Dim n As Integer
Set sh = ThisWorkbook.Worksheets("Sheet1")

sh.Range("a1").End(xlDown).Select

For m = 2 To Selection.Row
sh.Range("d" & m & ":" & "i" & m).SpecialCells(xlCellTypeConstants, 2).Copy
j = sh.Cells(Rows.Count, "g").End(xlUp).Row + 1
sh.Range("g" & j).PasteSpecial (xlPasteValues), Transpose:=True
Application.CutCopyMode = False
sh.Range("a" & m & ":" & "c" & m).Copy
k = sh.Cells(Rows.Count, "a").End(xlUp).Row + 1
i = sh.Cells(Rows.Count, "g").End(xlUp).Row
sh.Range("a" & k & ":" & "c" & i).PasteSpecial (xlPasteValues)
sh.Range("j" & m & ":" & "l" & m).Copy
n = sh.Cells(Rows.Count, "d").End(xlUp).Row + 1
sh.Range("d" & n & ":" & "f" & i).PasteSpecial (xlPasteValues)
Next m
End Sub

我的原始数据位于A1:L1之间,结果输出数据位于a到g列之间,如下所示...名字姓氏电子邮件数量电话网站其他列邮件