2016-04-28 97 views
0

您好,我有三列填充名稱。到目前爲止,我需要提取每列的三個第一個單元格,並將所有15個名稱放入第四列。但是如果有重複,我不能把它們放在列表中。比較excel中三列的前3個單元格

到目前爲止,我鑽進

Private Sub CommandButton1_Click() 
Dim temp(15) As String 
Dim array1(5) As String 
Dim array2(5) As String 
Dim array3(5) As String 
Dim i As Integer 
Dim j As Integer 

For i = 1 To 5 
    array1(i) = Cells(i + 3, 1).Value 
    array2(i) = Cells(i + 3, 4).Value 
    array3(i) = Cells(i + 3, 7).Value 
Next i 

temp(1) = array1(1) 
temp(2) = array1(2) 
temp(3) = array1(3) 
temp(4) = array1(4) 
temp(5) = array1(5) 
temp(6) = array2(1) 
temp(7) = array2(2) 
temp(8) = array2(3) 
temp(9) = array2(4) 
temp(10) = array2(5) 
temp(11) = array3(1) 
temp(12) = array3(2) 
temp(13) = array3(3) 
temp(14) = array3(4) 
temp(15) = array3(5) 

For i = 1 To 15 
    For j = 1 To 15 
     If (temp(i) = temp(j + 1)) Then 
     Else 
     Cells(i + 4, 10).Value = temp(i) 
     End If 
    Next j 
    j = 0 
Next i 

End Sub 
+0

你有3列,並且需要提取每列的前3個單元。那是9個電池。你從哪裏得到15個名字?你是否想要提取每列的前5個單元格? –

回答

0
For i = 1 to 3 
    Cells(6 * i - 5, 10).Resize(5, 1).Value = Cells(6 * i - 5, 4 * i - 3).Resize(5,1).Value 
Next 

Application.DisplayAlerts = False 
Cells(1, 10).Resize(15, 1).RemoveDuplicates Columns:=1, Header:=xlNo 
Application.DisplayAlerts = True 
相關問題