Hi,
I am using this code to search thru a sheet looking for a value in a column, and if found, copy the row to a different sheet. However, when the value is found it is a range, not only a single row. That means I need to replace the "Cells" in this code, Cells(x, 1).Resize(1, 33).Copy, with "Range". Or at least I thought so, but that is not working. What am I doing wrong? Second question, when the range has been copied I would like to find the second range if any. Do I need to add in the "FindNext" before the Elseif, or after? (I Can't get that to work either...)
Full VBA code below:
Public Sub FindCopy()
Sheets("Sheet1").Select
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To FinalRow
ThisValue = Cells(x, 4).Value
If ThisValue = "Agro" Then
Cells(x, 1).Resize(1, 33).Copy
Sheets("Sheet2").Select
NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(NextRow, 1).Select
ActiveSheet.Paste
Sheets("Sheet2").Select
ElseIf ThisValue = "Vegro" Then
Cells(x, 1).Resize(1, 33).Copy
Sheets("Sheet3").Select
NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(NextRow, 1).Select
ActiveSheet.Paste
Sheets("Sheet3").Select
End If
Next x
End Sub
I am using this code to search thru a sheet looking for a value in a column, and if found, copy the row to a different sheet. However, when the value is found it is a range, not only a single row. That means I need to replace the "Cells" in this code, Cells(x, 1).Resize(1, 33).Copy, with "Range". Or at least I thought so, but that is not working. What am I doing wrong? Second question, when the range has been copied I would like to find the second range if any. Do I need to add in the "FindNext" before the Elseif, or after? (I Can't get that to work either...)
Full VBA code below:
Public Sub FindCopy()
Sheets("Sheet1").Select
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To FinalRow
ThisValue = Cells(x, 4).Value
If ThisValue = "Agro" Then
Cells(x, 1).Resize(1, 33).Copy
Sheets("Sheet2").Select
NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(NextRow, 1).Select
ActiveSheet.Paste
Sheets("Sheet2").Select
ElseIf ThisValue = "Vegro" Then
Cells(x, 1).Resize(1, 33).Copy
Sheets("Sheet3").Select
NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(NextRow, 1).Select
ActiveSheet.Paste
Sheets("Sheet3").Select
End If
Next x
End Sub