简体   繁体   English

从vba中的Excel表格标题中删除重复项

[英]Remove Duplicates from a table headers in Excel in vba

I'm trying to remove multiple duplicates in Excel 2016 VBA from a imported XML file. 我正在尝试从导入的XML文件中删除Excel 2016 VBA中的多个重复项。

It works with a array: 它适用于数组:

ActiveSheet.Range("%tableName%").RemoveDuplicates Columns:=Array(8, 10, 12, 26, 40), Header:=xlYes

But I the problem is that I don't always know what column my data I want to remove duplicates from is. 但我的问题是,我并不总是知道我希望从中移除重复项的数据列是什么。 this week it could be 8, 10, 12, 26, 40 next week it could be 9, 10, 15, 26, 40. 本周它可能是下周8,10,12,26,40,可能是9,10,15,26,40。

It is always the same table header names: 它始终是相同的表头名称:

'8 = Range("%tableName%[udsendelses_dato]")
'10 = Range("%tableName%[start_tid]")
'12 = Range("%tableName%[udsendelses_titel]")
'26 = Range("%tableName%[Titel]")
'40 = Range("%tableName%[Varighed]")

There might be simpler but since it is a Table (a ListObject in Excel VBA), this should do: 可能更简单,但因为它是一个Table(Excel VBA中的ListObject ),所以应该这样做:

With Sheet1.ListObjects("Table1")
    .Range.RemoveDuplicates Columns:=Array( _
        .ListColumns("udsendelses_dato").index, _
        .ListColumns("start_tid").index, _
        .ListColumns("udsendelses_titel").index, _
        .ListColumns("Titel").index, _
        .ListColumns("Varighed").index), _
        Header:=xlYes
End With

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM