PDA

View Full Version : Sleeper: Copy a range of cells in a for loop



austenr
05-20-2005, 09:48 AM
I have this for loop:


Sub FindTotals()
FinalRow = Cells(65536, 1).End(xlUp).Row
For i = 2 To FinalRow
If Cells(i, 4).Value = "JUNE" Then
'Copy a range on the same row
'Paste to another range on another worksheet
End If
Next i
End Sub

Need to copy a range of cells on the same row and paste it to another worksheet in say A1. How do you do that?

Norie
05-20-2005, 10:18 AM
I'm not 100% sure what you want but something like this might work.



Sub FindTotals()
FinalRow = Cells(65536, 1).End(xlUp).Row
For i = 2 To FinalRow
If Cells(i, 4).Value = "JUNE" Then
Cells(i,4).EntireRow.Copy Worksheets("AnotherSheet").Range("A65536").End(xlUp)
End If

Next i
End Sub

austenr
05-20-2005, 10:27 AM
No just want to copy selected cells from the same row...

OBP
05-20-2005, 11:47 AM
austenr, the code that norie has posted copies the entire row, if that isn't what you want, then you need to select the range using VBA.
Do you know what the range is?
Has the range got a blank cell at the end of it?

austenr
05-20-2005, 11:49 AM
Sorry....I think I have it figured out but the code may have some redundancies in it...I will post it later to see if it can be cleaned up.