troubleshooting Question

Start the loop again when finding a duplicate in the same cell

Avatar of Alex Krakov
Alex Krakov asked on
5 Comments1 Solution78 ViewsLast Modified:
I have a Excel file, its look like:
BeforeAfter the macros, this will be the end results:
I want macro that read column "B", and paste first country from column "C" in the same cells of column "A", after he find duplicate cell in "B", he copy next country from column "C", and does the same as I wrote with first country and etc.

I have a code:
Sub x()

Dim r1 As Long, r2 As Long

r1 = 2: r2 = 2

Do While Cells(r1, 2) <> vbNullString
    If IsNumeric(Application.Match(Cells(r1, 2), Range(Cells(1, 2), Cells(r1 - 1, 2)), 0)) Then
        r2 = r2 + 1
    End If
    Cells(r1, 1).Value = Cells(r2, 3).Value
    r1 = r1 + 1

End Sub

But it does not work as it should:
After macro
I want when macro find first duplicate in column "B" (in my case B7 "A Bad Moms Christmas") he starting find duplicate from this cell and not paying attention to past cells, and paste same country from "C" (United Arab Emirates), before he find another duplicate and etc.
Can someone help? Thanks.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros