【问题标题】:VLOOKUP using batch scriptingVLOOKUP 使用批处理脚本
【发布时间】:2014-05-31 12:27:14
【问题描述】:

我是脚本新手,作为分析师,我使用 Excel 表执行大量活动。 我有两个文件,其中包含项目列表。 File1 包含 1 列 File2 包含 2 列。

我想检查 file2 的 column1 中的列表是否与 file2 的 column1 中的列表相同。如果是,那么它应该在 file3 中打印 column1File1, column1File2 和 coulmn2File2 否则它应该在 file3 中打印 "NA", column1File2, column2File2。

请帮忙,这会大大简化我的工作。

【问题讨论】:

  • 我想检查 file2 的 column1 中的列表是否与 file2 的 column1 中的相同。 是的。 :)

标签: windows scripting vbscript


【解决方案1】:

我不久前制作了这个程序,虽然它会遍历 1 个工作簿中的工作表,并逐个单元格进行比较,但它可能会让您朝着正确的方向前进。它会在 1 个“主”工作表中占用一个单元格,然后遍历每个工作表以在特定列中找到它。在它找到它之后,计数器会增加,然后它会占用主表中的下一个单元格,依此类推。您可以更改为使用多本书并获取您想要的任何单元格并进行比较。

Sub Open_Excel()


'Use worksheetNum as sheet to read/write data
Set currentWorkSheet = objExcel.ActiveWorkbook.Worksheets(worksheetNum)

'How many rows are used in the current worksheet
usedRowsCount = currentWorkSheet.UsedRange.Rows.Count

'Use current worksheet cells for values
Set Cells = currentWorksheet.Cells

    'Loop through each row in the worksheet  
    For curRow = startRow to (usedRowsCount)            

        'Get computer name to ping to
        strEmailAddressSource = Cells(curRow,colEmailAddressSource).Value
        strServerSource = Cells(curRow,colHostserverSource).Value
        strLocationSource = Cells(curRow,colLocationSource).Value

        'make the values unique
        strconcatenation = strServerSource & strLocationSource

        Call Comparison()

    Next

End Sub

'********************************************************************************************
'**** Comparison
'********************************************************************************************
'Comparison test

Sub Comparison()

'choose the worksheets to go through
For  worksheetCounter = 6 to 9 'workSheetCount

Set currentWorkSheetComparison = objExcel.ActiveWorkbook.Worksheets(worksheetCounter)

    usedRowsCountNew = currentWorkSheetComparison.UsedRange.Rows.Count

    'First row to start the comparison from
    For rowCompare = 2 to (usedRowsCountNew)

    strEmailLot = currentWorkSheetComparison.Cells(rowCompare,colEmailAddressLot).Value

    comp1 = StrComp(strEmailAddressSource,strEmailLot,0)

    comp2 = StrComp(strconcatenation,reportConcat,0)



     'check if the values match
        If ((comp1 = 0) AND (comp2 = 0)) THEN
        countvalue = countvalue + 1 
        End If

    Next
Next

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    • 1970-01-01
    • 2014-12-03
    • 2011-06-15
    相关资源
    最近更新 更多