Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Your site was well structured and I found what I was looking for in about 2 minutes. I am looking forward to participating with you in the future..."

Geography

Where in the world do Tek-Tips members come from?
wiginprov (TechnicalUser)
3 May 01 9:34
I need to identify duplicate names and addresses in an Excel file.

I have the following syntax, which will highlight the specified text:


Dim strClient As String
strClient = Application.InputBox("Please enter a client name.", "Search for client name")
    
With Worksheets(1).Range("c1:c500")
    Set c = .Find(strClient, LookIn:=xlValues)
    If Not c Is Nothing Then
        firstAddress = c.Address
        Do
            c.Interior.Pattern = xlPatternGray50
            c.Interior.PatternColorIndex = 28
            Set c = .FindNext(c)
        Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
End With
End Sub

Can anyone tell me how to count the number of records with the specified text, or identify duplicates, so I need not scroll through the entire file?  This database will likely be populated with 5,000 records.

Many thanks.
DarkSun (Programmer)
3 May 01 12:30
Try this code then let me know if you have any problems.

Private Sub FindMatches()
Dim AryPositions() As String
Dim strClient As String
i = 1
strClient = Application.InputBox("Please enter a client name.", "Search for client name")
    
With Worksheets(1).Range("c1:c500")
    Set c = .Find(strClient, LookIn:=xlValues)
    If Not c Is Nothing Then
        firstAddress = c.Address
        Do
            c.Interior.Pattern = xlPatternGray50
            c.Interior.PatternColorIndex = 28
            ReDim Preserve AryPositions(i)
            AryPositions(i) = c.Address
            i = i + 1
            Set c = .FindNext(c)
        Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
End With

MsgBox "There were " & UBound(AryPositions()) & " matches found."
answer = MsgBox("Would you like to View Cells?", vbYesNo)
If answer = 6 Then
    For i = 1 To UBound(AryPositions())
        Worksheets(1).Range(AryPositions(i)).Select
        MsgBox "Continue?", vbOKOnly
    Next i
End If
End Sub
wiginprov (TechnicalUser)
3 May 01 15:51
Thank you!  It works great.  

I am not familiar with the "ReDim Preserve...."  syntax or "UBound".  I will have to so some research so I fully benefit from your efforts.  

I am most appreciative.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close