find value in a column and copy the row

sarahips

New Member
Joined
Sep 19, 2011
Messages
5
I have seen other posts asking a similar question but I dont know VBA well enough to be able to fit it to my needs so help would be appreciated:

I have a spreadsheet that contains staff information. I want to search for a staff member (column B) by entering the staff number in an input box and then copying the entire row (A:Z) onto a different spreadsheet, in a separate workbook if possible. There may be more than one entry per staff number and I need to copy all occurances.

I also want run the macro from another 'control' spreadsheet.

Eg, Sheet1 is the control sheet, Sheet2 contains the information, Sheet3 is where the selected information is copied to.

First time posting so please let me know if I need to post more information

Thanks
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I have seen other posts asking a similar question but I dont know VBA well enough to be able to fit it to my needs so help would be appreciated:

I have a spreadsheet that contains staff information. I want to search for a staff member (column B) by entering the staff number in an input box and then copying the entire row (A:Z) onto a different spreadsheet, in a separate workbook if possible. There may be more than one entry per staff number and I need to copy all occurances.

I also want run the macro from another 'control' spreadsheet.

Eg, Sheet1 is the control sheet, Sheet2 contains the information, Sheet3 is where the selected information is copied to.

First time posting so please let me know if I need to post more information

Thanks

Not sure what you mean by control sheet, but maybe this will help?

Code:
Sub sarahips()
Dim x As String
Dim lr As Long

lr = Cells(Rows.Count, 1).End(xlUp).Row

x = InputBox("Please enter the Staff Member's Name")

With Range("B2:B" & lr)

    .AutoFilter Field:=1, Criteria1:=x
    .SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp)(2)
    .AutoFilter
    .AutoFilter
    
End With

End Sub
 
Upvote 0
Hi, thanks for this. It's not quite doing everything I need but it's certainly given me a good starting point.
thanks for your quick response
 
Upvote 0
Is it possible to copy the values of the cells only?
This one is copying all the fornulas too, including a macro button I have at the end of the row!

Thanks
 
Upvote 0
Is it possible to copy the values of the cells only?
This one is copying all the fornulas too, including a macro button I have at the end of the row!

Thanks

You're welcome. See if this helps.
Code:
Sub sarahips()
Dim x As String
Dim i As Long
Dim lr As Long

lr = Cells(Rows.Count, 1).End(xlUp).Row

x = InputBox("Please enter the Staff Member's Name")

For i = lr To 2 Step -1

    If Range("B" & i).Value = x Then
    
        Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp)(2).Value = Range(Range("A" & i), Range("Z" & i)).Value

    End If
    
Next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,570
Messages
6,179,610
Members
452,931
Latest member
The Monk

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top