Dirk Wessels macros

teodormircea

Active Member
Joined
Jan 8, 2008
Messages
331
I'm using Dirk Wessels' excel list compare .It works nice but it doesn't match evry thing, for example if i have more then 10000 lines and diferents format cell doesn't work anymore. I have the code. Does any one tryed to improuve this solution:eek:
 
Yap ok it sucks i know that's way want to change it , so when u you have time and the feel for it , is up to you , take your time
Great job till now thank you very much, if i have an idea how to manage this problem with no match i will post for you
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Here is the code

Code:
Const msFromWorksheet As String = "Sheet1"  'From worksheet name
Const msToWorkSheet As String = "Sheet2"    'To Worksheet name
Const miSerial1Col As Integer = 1           'Serial1 column (A)
Const miSerial2Col As Integer = 8          'Serial2 column (J)
Const miDataColumns As Integer = 7          'No of data columns per entry
Const mbFirstMatchOnly As Boolean = False   'Set to True if code to stop after first match

Dim mwsFr As Worksheet, mwsTo As Worksheet
Sub MatchEntries()
Dim bFound As Boolean
Dim iMatchLength As Integer
Dim iPtr1 As Integer, iPtr2 As Integer
Dim iDataCols As Integer
Dim lRow1 As Long, lRow2 As Long, lRowResults As Long
Dim lRowEnd1 As Long, lRowEnd2 As Long
Dim lInterval As Long, lNextInterval As Long
Dim rCur1 As Range, rCur2 As Range, R1 As Range, R2 As Range
Dim sCur1 As String, sCur2 As String
Dim vReply As Variant

Do While iMatchLength = 0
    vReply = Application.InputBox(prompt:="Enter no of characters to match", _
                                        Title:="Partial Match length?")
    If vReply = False Then
        MsgBox "Macro abandoned"
        Exit Sub
    End If
    iMatchLength = Int(Val(vReply))
Loop

Set mwsFr = Sheets(msFromWorksheet)
Set mwsTo = Sheets(msToWorkSheet)

'-- Get Serial1 range --
lRowEnd1 = mwsFr.Cells(Rows.Count, miSerial1Col).End(xlUp).Row
If lRowEnd1 < 3 Then
    MsgBox "No Serial1 data present cor matching"
    Exit Sub
End If
Set R1 = mwsFr.Range(Cells(2, miSerial1Col).Address, _
                    Cells(lRowEnd1, miSerial1Col).Address)

'-- Get Serial2 range --
lRowEnd2 = mwsFr.Cells(Rows.Count, miSerial2Col).End(xlUp).Row
If lRowEnd2 < 2 Then
    MsgBox "No Serial2 data present"
    Exit Sub
End If
Set R2 = mwsFr.Range(Cells(2, miSerial2Col).Address, _
                    Cells(lRowEnd2, miSerial2Col).Address)

mwsTo.UsedRange.ClearContents

lInterval = Int(lRowEnd2 / 100)
If lInterval < 1 Then lInterval = 1

lRowResults = 1
CopyDataLine FromRow1:=1, FromRow2:=1, ToRow:=1

For Each rCur1 In R1
    lRow1 = rCur1.Row
    '-- Report progress if required --
    If lNextInterval < lRow1 Then
        Application.StatusBar = "Processing row " & lRow1 & ": " & _
                                Format(lRow1 / lRowEnd1, "0.00%") & "complete"
        lNextInterval = lRow1 + lInterval
    End If
    sCur1 = LCase$(CStr(rCur1.Value))
    For Each rCur2 In R2
        bFound = False
        lRow2 = rCur2.Row
        If lRow2 <> lRow1 Then
            sCur2 = LCase$(CStr(rCur2.Value))
            
            For iPtr1 = 1 To Len(sCur1) - iMatchLength + 1
                If InStr(sCur2, Mid$(sCur1, iPtr1, iMatchLength)) <> 0 Then
                    '-- Here if partial match found --
                    lRowResults = lRowResults + 1
                    CopyDataLine FromRow1:=lRow1, FromRow2:=lRow2, ToRow:=lRowResults
                    bFound = True
                    Exit For
                End If
            Next iPtr1
            If bFound And mbFirstMatchOnly Then Exit For
        End If
    Next rCur2
Next rCur1


Application.StatusBar = False
End Sub
Private Sub CopyDataLine(ByVal FromRow1 As Long, _
                         ByVal FromRow2 As Long, _
                         ByVal ToRow As Long)
Dim iPtr2 As Integer
Dim vaData1() As Variant, vaData2() As Variant, vaDataLine() As Variant

ReDim vaDataLine(1 To 1, 1 To (miDataColumns * 2))

vaData1 = mwsFr.Range(Cells(FromRow1, miSerial1Col).Address, _
                     Cells(FromRow1, miSerial1Col + miDataColumns - 1).Address).Value
vaData2 = mwsFr.Range(Cells(FromRow2, miSerial2Col).Address, _
                    Cells(FromRow2, miSerial2Col + miDataColumns - 1).Address).Value
For iPtr2 = 1 To miDataColumns
    vaDataLine(1, iPtr2) = vaData1(1, iPtr2)
    vaDataLine(1, iPtr2 + miDataColumns) = vaData2(1, iPtr2)
Next iPtr2

mwsTo.Range(Cells(ToRow, 1).Address, _
            Cells(ToRow, (miDataColumns * 2)).Address).Value = vaDataLine

End Sub
 
Upvote 0
After I scrutinized this very topic - I personally think (my personal thoughts - no offences) it is not worth these many views ! The topic is very uncommon and only the OP would benefit from the resolutions posted in this thread as the latter experiences a creepy behavior of malfunctions on his end !
 
Upvote 0
You are missing my point

When following data found

CZC541322B
CZC541342B
CZC5413228
CZC5413238
CZA5413228
CZC5413228

Which one do you determin the "Correct" data ?
 
Upvote 0
That's the trick i don't know witch is the right one , this i have to check it manually, the only think that i now is that i have some approximative match that are different by one ore more chars

I have a list of discrepancies that i use then to make the check
like :


0 can by confused with O
I,L,i,l
8,S,P,D,B
9,G,g
6,G
2,S,5
F,P,E
V.U
7,Z
M,N
and so on
i don't know witch is the good one the 0 or the O i can only guess that it is possible to have a possible match, and the serials will be tracked physically
 
Upvote 0
If i furnished the discrepancies to look for , from the beginning it will be possible ??
I don't i suck in programming perhaps is a stupid question.
 
Upvote 0

Forum statistics

Threads
1,216,031
Messages
6,128,424
Members
449,450
Latest member
gunars

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top