Hi,
I have setup the code below in attempt to do a conditional copy of mutiple ranges/rows from one sheet to another but was wondering if there is a way copying the ranges in one go instead of having multiple if statements?
For example, for rows 5 to 10, I want to copy values in column B to N for each row and paste into the sheet result but only if column A of each row starts with or contains "1".
Would using some kind of union function be the best way of doing this?
Hope someone can help!
Thanks,
Elvis
Sub copyranges
Worksheets("Calculate").Select
If Left(Range("a5"), 1).Value = 1 Then
Range("B5:N5").Copy
Sheets("Results").Select
Range("a60000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
End If
If Left(Range("a6"), 1).Value = 1 Then
Range("B6:N6").Copy
Sheets("Results").Select
Range("a60000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
End If
If Left(Range("a7"), 1).Value = 1 Then
Range("B7:N7").Copy
Sheets("Results").Select
Range("a60000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
End If
If Left(Range("a8"), 1).Value = 1 Then
Range("B8:N8").Copy
Sheets("Results").Select
Range("a60000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
End If
If Left(Range("a9"), 1).Value = 1 Then
Range("B9:N9").Copy
Sheets("Results").Select
Range("a60000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
End If
If Left(Range("a10"), 1).Value = 1 Then
Range("B10:N10").Copy
Sheets("Results").Select
Range("a60000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
End If
End Sub
I have setup the code below in attempt to do a conditional copy of mutiple ranges/rows from one sheet to another but was wondering if there is a way copying the ranges in one go instead of having multiple if statements?
For example, for rows 5 to 10, I want to copy values in column B to N for each row and paste into the sheet result but only if column A of each row starts with or contains "1".
Would using some kind of union function be the best way of doing this?
Hope someone can help!
Thanks,
Elvis
Sub copyranges
Worksheets("Calculate").Select
If Left(Range("a5"), 1).Value = 1 Then
Range("B5:N5").Copy
Sheets("Results").Select
Range("a60000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
End If
If Left(Range("a6"), 1).Value = 1 Then
Range("B6:N6").Copy
Sheets("Results").Select
Range("a60000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
End If
If Left(Range("a7"), 1).Value = 1 Then
Range("B7:N7").Copy
Sheets("Results").Select
Range("a60000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
End If
If Left(Range("a8"), 1).Value = 1 Then
Range("B8:N8").Copy
Sheets("Results").Select
Range("a60000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
End If
If Left(Range("a9"), 1).Value = 1 Then
Range("B9:N9").Copy
Sheets("Results").Select
Range("a60000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
End If
If Left(Range("a10"), 1).Value = 1 Then
Range("B10:N10").Copy
Sheets("Results").Select
Range("a60000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
End If
End Sub