获取范围类的AdvancedFilter方法失败错误,同时将一个Excel的唯一数据处理为另一个数据

时间:2019-03-05 11:54:04

标签: excel vba vbscript

我已附上excel文件的代码段,其中B列是所需的输出。这种类似的逻辑在宏中起作用,但是根据我们的要求,我们需要为其构建一个VBScript。下面是我的代码

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
Set inputExcelWorkbook = oExcel.Workbooks.Open("C:\...\Test1.xlsx")
Set inputExcelSheet = inputExcelWorkbook.ActiveSheet


inputExcelSheet.Range("A2:A11").AdvancedFilter _
xlFilterCopy,,inputExcelSheet.Range("B2"),True

inputExcelWorkbook.save
inputExcelWorkbook.close

Excel文件的片段 screenshot

1 个答案:

答案 0 :(得分:0)

所以,当我不使用xlFilterCopy而是按照@ nick.McDermaid建议使用“ 2”时,我的问题得到解决

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
Set inputExcelWorkbook = oExcel.Workbooks.Open("C:\...\Test1.xlsx")
Set inputExcelSheet = inputExcelWorkbook.ActiveSheet


inputExcelSheet.Range("A2:A11").AdvancedFilter _
2,,inputExcelSheet.Range("B2"),True

inputExcelWorkbook.save
inputExcelWorkbook.close