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
SubsunAsked:
Who is Participating?
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.
0
SubsunAuthor Commented:
Here you go.. Expected result in the result sheet..
Sample.xlsx
0
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...
0

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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

SubsunAuthor Commented:
Thanks, It's working as expected..
0
SubsunAuthor 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..
0
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

0
SubsunAuthor Commented:
Thanks!.. I appreciate it..
0
Saurabh Singh TeotiaCommented:
Yw...Happy to help.. :-)
0
SubsunAuthor 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

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.