I have a button with macro code. When you click the button, it searches for a value in a column and copy the entire row to a new sheet for all matching values.
THIS IS THE MACRO CODE:
Sub MyBestSystems_Click()
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 A = "MY BEST SYSTEMS", copy entire row to Sheet2
If Range("A" & CStr(LSearchRow)).Value = "MY BEST SYSTEMS" Then
'Select row in ALL_SP's to copy
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy
'Paste row into MY BEST SYSTEMS_A in next row
Sheets("MY BEST SYSTEMS_A").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste
'Move counter to next row
LCopyToRow = LCopyToRow + 1
'Go back to ALL_SP's to continue searching
Sheets("ALL_SP's").Select
End If
LSearchRow = LSearchRow + 1
Wend
'Position on cell A3
Application.CutCopyMode = False
Range("A3").Select
MsgBox "All matching data has been copied."
Exit Sub
Err_Execute:
MsgBox "An error occurred."
End Sub
The problem I have is that I want the code NOT to copy the ENTIRE row but only up to Column O. Please see attached file as an example...
Bookmarks