2016-04-28 204 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