Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default 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.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
copying cells waterguy Excel Discussion (Misc queries) 3 November 20th 08 01:05 AM
Macro for copying cells above empty cells JRB1024 Excel Programming 4 August 21st 07 03:57 PM
copying cells by checking color of the cells JJJ010101 Excel Programming 1 January 24th 06 06:42 AM
How do I skip blank cells when copying over a range of cells? tawells Excel Discussion (Misc queries) 2 June 7th 05 09:36 PM
Excel should allow cloaking of certain cells when copying cells b. LDI Woody Excel Worksheet Functions 1 March 11th 05 04:55 PM


All times are GMT +1. The time now is 07:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"