Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-08-2013, 07:07 PM
macropod's Avatar
macropod macropod is online now Help!! find two number recurring numbers in row?? Windows 7 64bit Help!! find two number recurring numbers in row?? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,520
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
Note: if your active range extends beyond the used range, you'll end up evaluating empty cells, quite likely leading to them accounting for the most frequent matches.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 04-10-2013, 04:26 AM
carrolld2 carrolld2 is offline Help!! find two number recurring numbers in row?? Windows 7 64bit Help!! find two number recurring numbers in row?? Office 2010 64bit
Novice
Help!! find two number recurring numbers in row??
 
Join Date: Apr 2013
Posts: 2
carrolld2 is on a distinguished road
Smile

Hi macropod,
That seems to be exactally what I needed, however as you stated it is returning values of 0&0. Is there a way for me to specify a range of cells for it to search, or mark the cells with numbers as active cells?

Thanks for the help!!!

carrolld2
Reply With Quote
Reply

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
Help!! find two number recurring numbers in row?? Page Numbers Not Matching Chapter Numbers gracie5290 Word 1 02-02-2012 11:41 PM
Help!! find two number recurring numbers in row?? 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

Other Forums: Access Forums

All times are GMT -7. The time now is 10:55 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft