2014-07-25 51 views
0

MS Excel中:轉換行。如果我有幾個排在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 

想法?

回答

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 
+0

天才寫!謝謝!正好走出大門。 – Chris

+0

非常歡迎您! –

0

在行和列之間移動數據 將數據複製到一個或多個列或行中。 在粘貼複製的數據之前,右鍵單擊第一個目標單元格(要粘貼數據的行或列的第一個單元格),然後單擊選擇性粘貼。 在「選擇性粘貼」對話框中,選擇「轉置」,然後單擊「確定」。

相關問題