Results 1 to 4 of 4

Thread: VBA search for duplicates & display warning message
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Sep 2018
    Posts
    132
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default VBA search for duplicates & display warning message

    I have the following code. Essentially, looking to find any duplicates in column B. The problem, is it continues to duplicate the function. Basically, what I want it to do is once it finds a duplicate in sheet names "Control Sheet" then display message and stop. No need to continue looping. Is this possible?

    Code:
       Range("B1").Select    Do While ActiveCell.Value <> ""
            vtnaddress = ActiveCell.Address
            vtn = ActiveCell.Value
            Range("B1").Select
            Do Until ActiveCell.Address = ""
                If ActiveCell.Value = vtn Then
                    MsgBox "Duplicate fund found, please check fund list"
                    Exit Do
                Else
                    ActiveCell.Offset(1, 0).Select
                End If
            Loop
            ActiveCell.Offset(1, 0).Select
        Loop

  2. #2
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,403
    Post Thanks / Like
    Mentioned
    471 Post(s)
    Tagged
    47 Thread(s)

    Default Re: VBA search for duplicates & display warning message

    How about
    Code:
    Sub srosk()
       Dim Cl As Range
       
       For Each Cl In Range("B1", Range("B" & Rows.Count).End(xlUp))
          If Application.CountIf(Range("B:B"), Cl.Value) > 1 Then
             MsgBox "Duplicate fund found, please check fund list"
             Exit Sub
          End If
       Next Cl
    End Sub
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  3. #3
    Board Regular
    Join Date
    Sep 2018
    Posts
    132
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA search for duplicates & display warning message

    Written so simply.. thank you!

    Quote Originally Posted by Fluff View Post
    How about
    Code:
    Sub srosk()
       Dim Cl As Range
       
       For Each Cl In Range("B1", Range("B" & Rows.Count).End(xlUp))
          If Application.CountIf(Range("B:B"), Cl.Value) > 1 Then
             MsgBox "Duplicate fund found, please check fund list"
             Exit Sub
          End If
       Next Cl
    End Sub

  4. #4
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,403
    Post Thanks / Like
    Mentioned
    471 Post(s)
    Tagged
    47 Thread(s)

    Default Re: VBA search for duplicates & display warning message

    You're welcome & thanks for the feedback
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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