2014-04-16 3 views
0

저는 스크립팅을 처음 사용하고 Excel 시트를 사용하여 분석가로서 많은 활동을 수행합니다. 항목 목록이있는 두 개의 파일이 있습니다. File1에는 1 열이 포함되어 있습니다. File2에는 2 개의 열이 있습니다.일괄 스크립팅을 사용하는 VLOOKUP

file2의 column1에있는 목록이 file2의 column1과 같은지 확인하고 싶습니다. 그렇다면 그것은 file3에 column1File1, column1File2 및 coulmn2File2를 인쇄해야합니다. 그렇지 않으면 file3에 "NA", column1File2, column2File2를 인쇄해야합니다.

제발, 내 일을 많이 단순화 도와주세요.

+0

* file2의 column1에있는 목록이 file2의 column1과 같은지 확인하고 싶습니다. * 예, 그렇습니다. :) – Bond

답변

0

이 프로그램은 오래 전에 만들었지 만 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