Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Sub Test()
- Dim wbR As Workbook, wbD As Workbook
- Dim wsR As Worksheet, wsD As Worksheet
- Dim LastrowR As Long, LastrowD As Long, i As Long, CountTimes As Long
- Dim PNR As String
- Set wbR = Workbooks("Recon.xlsm")
- Set wbD = Workbooks("DataExt.xlsx")
- Set wsR = wbR.Worksheets("Sheet1")
- Set wsD = wbD.Worksheets("Sheet1")
- 'Let as assume that PNR column is column A, in Sheet 1, in both workbooks.
- 'Also keep in mind that both workbooks should be open and have the following types (Recon -> .xlsm & DataExt -> .xlsx)
- 'Find the last row of PNR column in Recon File
- LastrowR = wsR.Cells(wsR.Rows.Count, "A").End(xlUp).Row
- 'Find the last row of PNR column in DataExt File
- LastrowD = wsD.Cells(wsD.Rows.Count, "A").End(xlUp).Row
- 'Loop PNR column in Recon File
- For i = 2 To LastrowR
- 'Assign value to PNR
- PNR = wsR.Range("A" & i).Value
- 'Count how many times PNR appears in column A DataExt file
- CountTimes = Application.WorksheetFunction.CountIf(wsD.Range("A2:A" & LastrowD), PNR)
- 'If appears 1 time
- If CountTimes = 1 Then
- 'If appears 2 times
- ElseIf CountTimes = 2 Then
- 'If appears more than 2 times
- ElseIf CountTimes > 2 Then
- End If
- Next i
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement