copying cells

E

Eric

I am trying to copy the last 4 rows of information to a new area from the
same sheet. The only catch is that there may be only 1 row of information or
400 rows. Either way I only want to copy the last four rows of information.
For example:

a b c
71 3 5 7
72 66 55 77
73
74
75
In this case I would copy rows 71 through 75 up to rows 9 through 12. Rows
9 and 10 will have information rows 11 and 12 will not. Or....

a b c
71 3 5 7
72 66 55 77
73 77 88 99
74 22 12 32
75 99 77 88

In this case Row 72 through 75 would be copied up to rows 9 through 12 with
each row having some information.
I was given a macro and for some reason it isn't working. Maybe someone can
help me out and make it easier.
 
J

Joel

Lastrow = Range("A" & Rows.Count).End(xlUp).Row
FirstRow = Lastrow - 3
If FirstRow < 1 Then FirstRow = 1

Range("A" & FirstRow & ":C" & Lastrow).Copy _
Destination:=Range("F1")
 
J

Joel

My first Posting assumed data was continuous from row 1 to end row, I don't
think this was correct. Try this code instead

LastRow = Range("A" & Rows.Count).End(xlUp).Row
FirstRow = Range("A" & LastRow).End(xlUp).Row
If LastRow - FirstRow > 3 Then
FirstRow = LastRow - 3
End If
If FirstRow < 1 Then
FirstRow = 1
End If
Range("A" & FirstRow & ":C" & LastRow).Copy _
Destination:=Range("F1")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Count & List Combinations 9
For Loop 9
Copy and Paste 8
Code to set print range 1
WCG Stats Sunday 03 September 2023 3
Address of Excel.Range & Range 4
Confused with lots of loops - Please help 3
Rank and Sort 4

Top