Creating Masterfile (Duplicate Values by using VBA in Excel)

Good Day!

Asking for any help to create a VBA code to create a Master file from two different List, please see excel file for your reference, thank you in advance.

Sher WinAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Where do the both lists exist, on the same Sheet?
And where you would like to populate the output, on the same Sheet or on a different Sheet?

Please confirm if the data layout in your original workbook is as same as showed in the sample file. If not, please upload a sample file with the layout as same as in your original file.
Sher WinAuthor Commented:
Hi Sir, I prefer the results to be on the other sheet, please see attached file, thank very much.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Please find the attached with the code on Module1 and a button called "Create Master" on List Sheet.
You may click this button to get the desired output.

Sub CombineData()
Dim sws As Worksheet, dws As Worksheet
Dim lr1 As Long, lc As Long, lr2 As Long, dlr As Long
Dim rng As Range, rngList As Range, cell As Range

Application.ScreenUpdating = False

Set sws = Sheets("List")
lr1 = sws.Cells(Rows.Count, 2).End(xlUp).Row
lr2 = sws.Cells(Rows.Count, 4).End(xlUp).Row
lc = sws.Cells(3, Columns.Count).End(xlToLeft).Column

Set rng = sws.Range(sws.Cells(4, 4), sws.Cells(lr2, lc))
Set rngList = sws.Range("B4:B" & lr1)

On Error Resume Next
Set dws = Sheets("Master")
On Error GoTo 0

If dws Is Nothing Then
    Set dws = Sheets.Add(after:=sws)
    dws.Name = "Master"
End If

sws.Range("D3", sws.Range("D3").End(xlToRight)).Copy dws.Range("B1")
dws.Range("A1").Value = "Name"

For Each cell In rngList
    dlr = dws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
    rng.Copy dws.Range("B" & dlr)
    dws.Range("A" & dlr).Value = cell.Value
Next cell

dlr = dws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
dws.Range("A2:A" & dlr).SpecialCells(xlCellTypeBlanks).Formula = "=R[-1]C"
dws.Range("A2:A" & dlr).Value = dws.Range("A2:A" & dlr).Value
dws.Range("A1").CurrentRegion.Borders.Color = vbBlack
Application.ScreenUpdating = True
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Sher WinAuthor Commented:
Thank you very much, it worked flawlessly. :)
Sher WinAuthor Commented:
Thank you very much, it worked flawlessly. :)
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Sher! Glad it worked as desired.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.