![]() |
|
#2
|
||||
|
||||
|
Hi carrolld2,
Try the following macro. As coded, it will handle cells with values up to 999. Code:
Sub MaxMatch()
Dim LRow As Long, LCol As Long, StrData As String, bFnd As Boolean
Dim C As Long, R As Long, I As Long, J As Long, ArrPairs() ' Array
ReDim Preserve ArrPairs(1, 0)
With ActiveSheet
LRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
LCol = .Cells.SpecialCells(xlCellTypeLastCell).Column - 1
For C = 1 To LCol
For R = 1 To LRow
StrData = Format(.Cells(R, C).Value, "000") & Format(.Cells(R, C + 1).Value, "000")
bFnd = False
For I = 0 To UBound(ArrPairs, 2) - 1
If StrData = ArrPairs(0, I) Then
bFnd = True
ArrPairs(1, I) = ArrPairs(1, I) + 1
Exit For
End If
Next
I = I + 1
If bFnd = False Then
ReDim Preserve ArrPairs(1, I)
ArrPairs(0, I) = StrData
ArrPairs(1, I) = 1
End If
Next
Next
For I = 0 To UBound(ArrPairs, 2) - 1
If ArrPairs(1, I) > ArrPairs(1, J) Then
J = I
End If
Next
MsgBox "The greatest paired match frequency is for" & vbCr & _
Int(ArrPairs(0, J) / 1000) & " & " & ArrPairs(0, J) Mod 1000 & _
", with " & ArrPairs(1, J) & " matches."
End With
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
| Tags |
| beginner, formula |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How do I refer to page numbers, when the numbers change as I prepare the document? | StevenD | Word | 5 | 11-29-2012 12:52 AM |
Page Numbers Not Matching Chapter Numbers
|
gracie5290 | Word | 1 | 02-02-2012 11:41 PM |
Find & Replace formula for numbers?
|
Griff | Word | 4 | 04-18-2011 02:47 AM |
| Find and replace page numbers in body of text | tollanarama | Word | 3 | 02-13-2011 06:00 AM |
| FInd recurring words in Word 2003 | NJ007 | Word | 4 | 01-25-2010 03:11 PM |