排除复制重复值(Excel VBA)

时间:2015-08-17 02:42:08

标签: excel vba excel-vba

我自动将某个HTML表复制到Excel,然后必须删除重复项或在复制时排除重复项。下面的代码,将html表中的值复制到某个单元格,然后将其再次转置/复制到另一个单元格。但我无法弄清楚如何将重复值排除在粘贴到最终单元格之外。

有一个按钮,其中复制的值将粘贴到excel。每个html表中有10行。

代码:

Option Explicit
Private Sub hand_over_Click()
Application.ScreenUpdating = False
Dim e, m, a As Integer, k As Variant

Range("XET1").Select
ActiveSheet.PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:= _
    False, NoHTMLFormatting:=True

Columns("E").NumberFormat = "MMM DD YYYY  H:MM:SS AM/PM"
Columns("I").NumberFormat = "DDD"

e = 6
m = 1

While Not Range("C" & e) = ""
    e = e + 1
Wend

For a = 5 To 1000
    If ActiveSheet.Cells(a, 5).Value <> "" Then

        If Range("XEV" & m) <> "" Then
            Range("C" & e).Value = Range("XEU" & m).Value
            Range("F" & e).Value = Range("XFD" & m).Value
            k = Split(Split(Split(Range("XEV" & m).Value2, ") :")(1), "):")(0), " Req(")
            Range("E" & e) = DateValue(Mid(k(1), 5, 7) & Right(k(1), 4)) + TimeValue(Mid(k(1), 12, 8))
            Range("D" & e) = k(0)
            Range("I" & e).Value = Date

            e = e + 1
            m = m + 1
        End If

   End If
Next a

ActiveSheet.Range("XET1:XFD50").Clear
Application.ScreenUpdating = True
End Sub

1 个答案:

答案 0 :(得分:0)

在转置/复制之前删除重复数据怎么样..

Range("XET1:XFD50").Select
ActiveSheet.Range("XET1:XFD50").RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), Header:=xlY