I am in need of a macro or VBA code that when ran will pop up a box and allow the user of the sheet to enter a name for example and the macro would search for the name entered and when it finds that name it will copy the entire row and paste it to a specific sheet. However I don't know if its possible to have the pop up ask for a the name to search for and the sheet to paste it too.
I have been using more targeted codes like:
Not sure if there is a way to alter it to achieve what I am looking to do.
I have been using more targeted codes like:
Code:
Sub Name()
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
On Error GoTo Err_Execute
'Start search in row 4
LSearchRow = 4
'Start copying data to row 2 in Sheet2 (row counter variable)
LCopyToRow = 2
While Len(Range("A" & CStr(LSearchRow)).Value) > 0
'If value in column B = "Mail Box", copy entire row to Sheet2
If Range("B" & CStr(LSearchRow)).Value = "Jorge Ortega" Then
'Select row in Sheet1 to copy
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy
'Paste row into Sheet2 in next row
Sheets(“Name").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste
'Move counter to next row
LCopyToRow = LCopyToRow + 1
'Go back to Sheet1 to continue searching
Sheets(“Sheet").Select
End If
LSearchRow = LSearchRow + 1
Wend
'Position on cell A3
Application.CutCopyMode = False
Range("A3").Select
Exit Sub
Err_Execute:
MsgBox "An error occurred."
End Sub
Not sure if there is a way to alter it to achieve what I am looking to do.
Last edited by a moderator: