如果我在Excel电子表格中有多行,那么:
Number Email-1 Email-2 Email-X Email-XX
12345 address1 address2 addressX addressXX
67890 address1 address2 addressX
98765 address1 address2 addressX addressXX
我需要将所有电子邮件地址汇集在一列中,并将其附带的数字放在相邻的列中:
Number Email
12345 address1
12345 address2
12345 addressX
12345 addressXX
67890 address1
67890 address2
67890 addressX
98765 address1
98765 address2
98765 addressX
98765 addressXX
我怎么能实现这个目标?我尝试了Paste Special-> Transpose的变体,但是我得到的是这样的:
12345
address1
address2
addressX
addressXX
想法?
答案 0 :(得分:1)
此宏假设原始数据位于 Sheet1 中,输出数据将写入 Sheet2
Sub dural()
Dim N As Long, s1 As Worksheet, s2 As Worksheet, _
i As Long, j As Long, M As Long, v As Variant, _
k As Long
Set s1 = Sheets("Sheet1")
Set s2 = Sheets("Sheet2")
N = s1.Cells(Rows.Count, "A").End(xlUp).Row
k = 1
For i = 2 To N
v = s1.Cells(i, "A").Value
M = s1.Cells(i, Columns.Count).End(xlToLeft).Column
For j = 2 To M
s2.Cells(k, 1).Value = v
s2.Cells(k, 2).Value = s1.Cells(i, j).Value
k = k + 1
Next j
Next i
End Sub
答案 1 :(得分:0)
在行和列之间移动数据 将数据复制到一个或多个列或行中。 在粘贴复制的数据之前,右键单击第一个目标单元格(要将数据粘贴到其中的行或列的第一个单元格),然后单击“选择性粘贴”。 在“选择性粘贴”对话框中,选择“转置”,然后单击“确定”。