Hi all,
I have a list of Reference numbers in column A, I want to search for a specific value by asking user input and select first five columns from the same row if the input matches to cut and paste to the next sheet as top row. I also want to remove other column values from the old sheet. I am very new to VBA coding, so this is the code I have used so far (adapted from a different online source). Please help!!!
Sub Macro5()
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
Dim LSearchValue As String
On Error GoTo Err_Execute
LSearchValue = InputBox("Please enter the Job Reference Number you wish to move to In Progress:", "Enter value")
'Start search in row 4
LSearchRow = 2
'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 A = LSearchValue, copy first 4 coloumns to InProgress sheet
If Range("A" & CStr(LSearchRow)).Value = LSearchValue Then
'Select row in Sheet1 to copy
Range(CStr(LSearchRow) & "1:" & CStr(LSearchRow)).Select
Selection.Copy
'Paste row into Sheet2 in next row
Sheets("InProgress").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("Sheet1").Select
End If
LSearchRow = LSearchRow + 1
Wend
Exit Sub
Err_Execute:
MsgBox "An error occurred."
End Sub
I have a list of Reference numbers in column A, I want to search for a specific value by asking user input and select first five columns from the same row if the input matches to cut and paste to the next sheet as top row. I also want to remove other column values from the old sheet. I am very new to VBA coding, so this is the code I have used so far (adapted from a different online source). Please help!!!
Sub Macro5()
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
Dim LSearchValue As String
On Error GoTo Err_Execute
LSearchValue = InputBox("Please enter the Job Reference Number you wish to move to In Progress:", "Enter value")
'Start search in row 4
LSearchRow = 2
'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 A = LSearchValue, copy first 4 coloumns to InProgress sheet
If Range("A" & CStr(LSearchRow)).Value = LSearchValue Then
'Select row in Sheet1 to copy
Range(CStr(LSearchRow) & "1:" & CStr(LSearchRow)).Select
Selection.Copy
'Paste row into Sheet2 in next row
Sheets("InProgress").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("Sheet1").Select
End If
LSearchRow = LSearchRow + 1
Wend
Exit Sub
Err_Execute:
MsgBox "An error occurred."
End Sub