Match name and copy that row from one sheet to another on a corresponding column

I want to lookup a list of names in Sheet one and if the name matches, I need to copy that Row to another sheet.
Sample one..Names which I need to search..I am trying with vlookup, but I am able to copy only one column (I am not that expert in vlookup).. Please let me know if there any formula or macro to do this.. Many Thanks in advance..
LVL 40
Subash SundharanIT Infrastructure Architect Asked:
Who is Participating?

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

x
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.

Martin LissOlder than dirtCommented:
A sample workbook would be a great help here.
Subash SundharanIT Infrastructure Architect Author Commented:
Here you go.. Expected result in the result sheet..
Sample.xlsx
Saurabh Singh TeotiaCommented:
Basis of your example..Use this code it will do what you are looking for..

Sub movdata()
    Dim rng As Range, cell As Range, r As Range
    Dim lr As Long, lr1 As Long, ws As Worksheet, ws1 As Worksheet, ws2 As Worksheet
    Dim k As Long, z As Long
    Set ws = Sheets("Sheet1")
    Set ws1 = Sheets("Sheet2")
    Set ws2 = Sheets("Result")

    ws2.Cells.Clear

    lr = ws1.Cells(Cells.Rows.Count, "A").End(xlUp).Row

    If lr = 1 Then
        MsgBox " Please enter value to search"
        Exit Sub
    End If

    Set r = ws1.Range("A1:A" & lr)

    lr1 = ws.Cells(Cells.Rows.Count, "A").End(xlUp).Row
    Set rng = ws.Range("A2:A" & lr1)

    For Each cell In rng
        If Application.WorksheetFunction.CountIf(r, cell.Value) = 1 Then

            If ws2.Cells(1, 1).Value = "" Then
                cell.EntireRow.Copy ws2.Range("a1")
            Else
                cell.EntireRow.Copy ws2.Range("A" & ws2.Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1)
            End If


        End If


    Next cell


End Sub

Open in new window


Saurabh...

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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Subash SundharanIT Infrastructure Architect Author Commented:
Thanks, It's working as expected..
Subash SundharanIT Infrastructure Architect Author Commented:
I need help with a small addition, is it possible to add the names which are not there in Sheet1 to another sheet or in the same result sheet? Let me know if I need to open a new question for this.. Thanks in advance..
Saurabh Singh TeotiaCommented:
You can use this code..it will move the values which are not their to the missing worksheet...

Sub movdata()
    Dim rng As Range, cell As Range, r As Range
    Dim lr As Long, lr1 As Long, ws As Worksheet, ws1 As Worksheet, ws2 As Worksheet
    Dim k As Long, z As Long, ws3 As Worksheet
    Set ws = Sheets("Sheet1")
    Set ws1 = Sheets("Sheet2")
    Set ws2 = Sheets("Result")
    Set ws3 = Sheets("Missing")
    
    ws2.Cells.Clear

    lr = ws1.Cells(Cells.Rows.Count, "A").End(xlUp).Row

    If lr = 1 Then
        MsgBox " Please enter value to search"
        Exit Sub
    End If

    Set r = ws1.Range("A1:A" & lr)

    lr1 = ws.Cells(Cells.Rows.Count, "A").End(xlUp).Row
    Set rng = ws.Range("A2:A" & lr1)

    For Each cell In rng
        If Application.WorksheetFunction.CountIf(r, cell.Value) = 1 Then

            If ws2.Cells(1, 1).Value = "" Then
                cell.EntireRow.Copy ws2.Range("a1")
            Else
                cell.EntireRow.Copy ws2.Range("A" & ws2.Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1)
            End If

          Else
          
                 If ws3.Cells(1, 1).Value = "" Then
                cell.EntireRow.Copy ws3.Range("a1")
            Else
                cell.EntireRow.Copy ws3.Range("A" & ws3.Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1)
            End If
          
          
        End If


    Next cell


End Sub

Open in new window

Subash SundharanIT Infrastructure Architect Author Commented:
Thanks!.. I appreciate it..
Saurabh Singh TeotiaCommented:
Yw...Happy to help.. :-)
Subash SundharanIT Infrastructure Architect Author Commented:
Ah Sorry.. What I mean is. If I am searching for following, names and if 'HHH' is not in Sheet1 then 'HHH' should be copied to Missing Sheet.. Right now it's copying the missing items from Sheet1..

ABCD
EFG
HHH

Open in new window

Rob HensonFinance AnalystCommented:
You could have still done it with VLOOKUP

=VLOOKUP(Value,Range,Offset,LookupType)

Value - The cell reference for the name you are looking for
Range - The range in which you are looking with the lookup value in the leftmost column, include all columns of the data, for your example A to D
Offset - The number of the column from which you want to return the value, in your range A to D column B is number 2, C = 3, D=4. Even if your range was say E to H, F would still be 2 as it is the second column of the range, G = 3 ie 3rd column.
LookupType - Set to FALSE as you need an exact match. TRUE will give a the closest but not greater than match.

So for your data in column A you have the name and then columns B to D with the VLOOKUP formulae with changes in the offset value as you move right across the columns.
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 Excel

From novice to tech pro — start learning today.