Results 1 to 1 of 1

Compare worksheet and list the number of duplicates

Threaded View

  1. #1
    Registered User
    Join Date
    12-07-2012
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    5

    Post Compare worksheet and list the number of duplicates

    Hi Everyone,


    Need some analysis where do I went wrong with my code.
    I want to compare the data in one workbook and list the duplicate in another workbook. I've come up with this code but the duplicates never counted.
    
    Private Sub CommandButton2_Click()
    Application.ScreenUpdating = False
    
           If Not ComboBox1.Value = "" Then
                  Dim OpenFile As String
                  
                  ChDir "C:\Documents and Settings\jlapuz\Desktop"
                  OpenFile = Application.GetOpenFilename(FileFilter:="BPI-PhilAm Files,*.csv", Title:="Open csv Files", MultiSelect:=False)
                  OpenFile = Mid(OpenFile, InStrRev(OpenFile, "\") + 1)
                  
                  If OpenFile = "False" Then
                         Exit Sub
                  End If
                  Workbooks.Open (OpenFile)
                  
                  Dim blnFoundDuplicate As Boolean
                  Dim myRange As Range
                  Dim mySearchRange As Range
                  Dim myOutputRange As Range
                  Dim inte As Integer
                  Dim dup As Range
                  Dim bf As Range
                  Dim bfa As String
                  Dim Coverage As Range
                  Dim Status As Range
    
            '     k = 0
                  i = 1
                  j = 0
                 'l = 1
                  strStartRange = "H1"
                '  bfa = "C1"
                  
                  Set myOutputRange = Workbooks(Sheet1.ComboBox1.Value & ".xlsx").Worksheets("Sheet1").Range("DuplicateReportStartHeading")     'Template to Copy with
                  Set mySearchRange = Workbooks(Sheet1.ComboBox1.Value & ".xlsx").Worksheets("Sheet1").Range("DuplicateReportStartHeading")     'To determine the duplicate within the template
                  Set myRange = Workbooks(OpenFile).Worksheets(Left(OpenFile, Len(OpenFile) - 4)).Range(strStartRange)     'File where template data came from
                  'Workbooks(Sheet1.ComboBox1.Value & ".xlsx").Sheet1.Range("A2:BF20").clearcontent
                  'Set bf = Workbooks("Book1.xlsm").Worksheets("Sheet1").Range(bfa)
                  'Set Coverage = Workbooks("Book1.xlsm").Worksheets("Sheet1").Range("C1")
                  'Set Status = Workbooks("Book1.xlsm").Worksheets("Sheet1").Range("D1")
                  'to lessen the loop Set Duplicate = Workbooks("Book1.xlsm").Worksheets("Sheet1").Range("DuplicateNo")
                  'Left(Sheet2.Range("B" & wbCount + 7).Value, Len(Sheet2.Range("B" & wbCount + 7).Value) - 5)
               
                  Do While myRange.Offset(j, 0).Value <> ""
    
    'search for the record if it already exist then update  the counts
           k = 1
           blnFoundDuplicate = False
                  Do While mySearchRange.Offset(k, 0).Value <> ""
                         If mySearchRange.Offset(k, 0).Value = Trim(myRange.Offset(j, 0).Value) Then
                                mySearchRange.Offset(k, 5).Value = (mySearchRange.Offset(k, 5).Value) + 1  'counter
                                inte = inte + 1
                                blnFoundDuplicate = True
                                Exit Do
                         End If
                  k = k + 1
                  
                  Loop
                  
    'record do not exist
           If Not blnFoundDuplicate Then
                  myOutputRange.Offset(i, 0).Value = WorksheetFunction.Trim(myRange.Offset(j, 0).Value)
                  myOutputRange.Offset(i, 1).Value = myRange.Offset(j, 1).Value
                  myOutputRange.Offset(i, 5).Value = 1
                  i = i + 1
           End If
           j = j + 1
           
    'Coverage:
                
    
    '              If Coverage.Offset(l, 0) = "300001" And Status.Offset(l, 0) = "A" Then ' coverage
    '                    myOutputRange.Offset(k, 2).Value = "Yes"
    '             ElseIf Coverage.Offset(l, 0) = "300001" And (Status.Offset(l, 0) = "" Or Status.Offset(l, 0) = "T") Then
    '                     myOutputRange.Offset(k, 2).Value = "No"
    '              End If
                 'l = l + 1
    '              If Coverage.Offset(l, 0) = "300002" And Status.Offset(l, 0) = "A" Then
    '                     myOutputRange.Offset(k, 3).Value = "Yes"
    '              ElseIf Coverage.Offset(l, 0) = "300002" And (Status.Offset(l, 0) = "" Or Status.Offset(l, 0) = "T") Then
    '                     myOutputRange.Offset(k, 3).Value = "No"
    '              End If
                  ' l = l + 1
    '              If Coverage.Offset(l, 0) = "300003" And Status.Offset(l, 0) = "A" Then
    '                     myOutputRange.Offset(k, 4).Value = "Yes"
    '              ElseIf Coverage.Offset(l, 0) = "300003" And (Status.Offset(l, 0) = "" Or Status.Offset(l, 0) = "T") Then
    '                    myOutputRange.Offset(k, 4).Value = "No"
    '              End If
    '              l = l + 1
                 
                  Loop
    
    MsgBox "Duplicate Report Completed.", vbInformation, "Report Completed"
    
           Else
                  MsgBox "Please drop down to select a Template for validation", vbInformation, "Open Template"
           End If
           
    Application.ScreenUpdating = True
    End Sub

    I've also attached the file that I am working with

    Hope someone can help me to deal with this.

    Regards,
    Jeric Atraje Lapuz
    Attached Files Attached Files
    Last edited by jericlapuz; 01-30-2013 at 06:10 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1