I have a macro which matches a value in CV1 with every row in column cu if a match is found the whole row is copied to Sheet 5. This part works perfectly. Unfortunately I only want to copy the range(a:CS) so as not to overwrite existing information in sheet 5 after column cs. I have been unable to figure out how to do this and it is driving me crazy. I hope someone can help keep my sanity.
Thank you
Ted
Macro
Sub test()
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
Dim LSearchValue As String
Dim LSearchValue1 As String
LSearchValue1 = Range("CV1").Value
'Start search in row 2
LSearchRow = 2
'Start copying data to row 2 in First (row counter variable)
LCopyToRow = 2
Sheets("All_Data").Activate
LSearchValue1 = Range("CV1").Value
'
'
' 5
'
'
Worksheets("5").Range("A2:cs1093").ClearContents
'LSearchValue = concatenate(LSearchValue & "1")
While Len(Range("A" & CStr(LSearchRow)).Value) > 0
'If value in column C = LSearchValue, copy entire row First
If Range("CU" & CStr(LSearchRow)).Value = LSearchValue1 Then
'Select row in All1to4 to copy
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy
'Paste row into First in next row
Sheets("5").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste
Sheets("5").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste
'Move counter to next row
LCopyToRow = LCopyToRow + 1
'Go back to All_Data to continue searching
Sheets("All_Data").Select
End If
LSearchRow = LSearchRow + 1
Wend
End Sub
Bookmarks