ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   copying cells (https://www.excelbanter.com/excel-programming/408635-copying-cells.html)

Eric

copying cells
 
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.




joel

copying cells
 

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")
"Eric" wrote:

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.




joel

copying cells
 
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")


"Eric" wrote:

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.





All times are GMT +1. The time now is 10:48 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com