如何从导入的文件中删除重复项?

时间:2019-02-13 17:21:00

标签: excel

我有一个宏,每天都可以用来导入数据。如果昨天的导入在第100行结束,那么今天的导入将在第101行开始。

列B具有唯一值,我不希望数据中出现任何重复。如何仅选择导入的文件并删除该文件中的重复项?

Sub Import_Data()
Dim Ret

Ret = Application.GetOpenFilename("Text Files (*.txt), *.txt")

If Ret <> False Then
    With ActiveSheet.QueryTables.Add(Connection:= _
    "TEXT;" & Ret, Destination:=Application.InputBox(prompt:="Select Input Cell", Type:=8))

    .Name = "Sample"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .TextFilePromptOnRefresh = False
    .TextFilePlatform = 437
    .TextFileStartRow = 1
    .TextFileParseType = xlDelimited
    .TextFileTextQualifier = xlTextQualifierDoubleQuote
    .TextFileConsecutiveDelimiter = False
    .TextFileTabDelimiter = False
    .TextFileSemicolonDelimiter = False
    .TextFileCommaDelimiter = True
    .TextFileSpaceDelimiter = False
    .TextFileColumnDataTypes = Array(2, 2, 1, 2, 2, 1)
    .TextFileTrailingMinusNumbers = True
    .Refresh BackgroundQuery:=False

    End With
End If
End Sub

0 个答案:

没有答案