比较excel

时间:2016-04-28 11:07:24

标签: excel excel-vba excel-formula vba

您好我有三列填充了名称。到目前为止,我需要提取每列的三个第一个单元格,并将所有15个名称放入第四列。但如果有重复,我不能把它们放在列表中。

到目前为止,我进入了

   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

1 个答案:

答案 0 :(得分: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