Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default Copy and Paste LAST ROW of data

Hi All,

I would like to:

1) Find the LAST row of consecutive data (starts at column "A" - numeric
values in col "A", start row number varies)

2) Selct the FIRST to LAST cell of continuous data on that LAST row

3) Copy the FIRST to LAST cell of continuous data on that LAST row

4) Paste the copied data in the same cell position on the row immediately
below

If possible, can a solution be provided to do the above process on multiple
worksheets within the same workbook?

Thanks,
Sam

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200709/1

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Copy and Paste LAST ROW of data

If A13 and B13 have values, C13 is empty, and D13 has a value,
then
do you want A13 thru B13 or A13 thru D13?
--
Gary''s Student - gsnu200743


"Sam via OfficeKB.com" wrote:

Hi All,

I would like to:

1) Find the LAST row of consecutive data (starts at column "A" - numeric
values in col "A", start row number varies)

2) Selct the FIRST to LAST cell of continuous data on that LAST row

3) Copy the FIRST to LAST cell of continuous data on that LAST row

4) Paste the copied data in the same cell position on the row immediately
below

If possible, can a solution be provided to do the above process on multiple
worksheets within the same workbook?

Thanks,
Sam

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200709/1


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default Copy and Paste LAST ROW of data

Hi Gary''s Student,

Thank you for reply.

I would like A13 thru B13

Cheers,
Sam

Gary''s Student wrote:
If A13 and B13 have values, C13 is empty, and D13 has a value,
then
do you want A13 thru B13 or A13 thru D13?


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200709/1

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Copy and Paste LAST ROW of data

Is there other data surrounding this contiguous data that we need to avoid?
If not, then this simple code will do it:

Sub test()
Dim LRow As Long

LRow = Cells(Rows.Count, 1).End(xlUp).Row
Rows(LRow).Copy Rows(LRow + 1)
End Sub

Mike F
"Sam via OfficeKB.com" <u4102@uwe wrote in message
news:77e91b9497994@uwe...
Hi All,

I would like to:

1) Find the LAST row of consecutive data (starts at column "A" - numeric
values in col "A", start row number varies)

2) Selct the FIRST to LAST cell of continuous data on that LAST row

3) Copy the FIRST to LAST cell of continuous data on that LAST row

4) Paste the copied data in the same cell position on the row immediately
below

If possible, can a solution be provided to do the above process on
multiple
worksheets within the same workbook?

Thanks,
Sam

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200709/1



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default Copy and Paste LAST ROW of data

Hi Mike,

Thanks for reply and assistance.

Does your solution take into account Gary's Student Post:

If A13 and B13 have values, C13 is empty, and D13 has a value,
then
do you want A13 thru B13 or A13 thru D13?


I would like A13 thru B13

Mike Fogleman wrote:
Is there other data surrounding this contiguous data that we need to avoid?
If not, then this simple code will do it:


Sub test()
Dim LRow As Long

LRow = Cells(Rows.Count, 1).End(xlUp).Row
Rows(LRow).Copy Rows(LRow + 1)
End Sub

Mike F


Mike, will this code work with my request for A13 thru B13 based on above,
selecting only contiguous data filled cells on that row?

Please advise.

Cheers,
Sam

--
Message posted via http://www.officekb.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Copy and Paste LAST ROW of data

Sub CopyLast()
Dim r1 as Range, r2 as Range
set r1 = cells(rows.count,1).End(xlup)
if isempty(r1(1,2)) then
set r2 = r1
else
set r2 = r1.end(xltoRight)
end if
Range(r1,r2).Copy r1(2)
End Sub

--
Regards,
Tom Ogilvy


"Sam via OfficeKB.com" wrote:

Hi Mike,

Thanks for reply and assistance.

Does your solution take into account Gary's Student Post:

If A13 and B13 have values, C13 is empty, and D13 has a value,
then
do you want A13 thru B13 or A13 thru D13?


I would like A13 thru B13

Mike Fogleman wrote:
Is there other data surrounding this contiguous data that we need to avoid?
If not, then this simple code will do it:


Sub test()
Dim LRow As Long

LRow = Cells(Rows.Count, 1).End(xlUp).Row
Rows(LRow).Copy Rows(LRow + 1)
End Sub

Mike F


Mike, will this code work with my request for A13 thru B13 based on above,
selecting only contiguous data filled cells on that row?

Please advise.

Cheers,
Sam

--
Message posted via http://www.officekb.com


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Copy and Paste LAST ROW of data

Hi Tom, neither of our code addresses the situation if there is
non-contiguous data further down in column A. Awaiting the op's answer on
that.

Mike F
"Tom Ogilvy" wrote in message
...
Sub CopyLast()
Dim r1 as Range, r2 as Range
set r1 = cells(rows.count,1).End(xlup)
if isempty(r1(1,2)) then
set r2 = r1
else
set r2 = r1.end(xltoRight)
end if
Range(r1,r2).Copy r1(2)
End Sub

--
Regards,
Tom Ogilvy


"Sam via OfficeKB.com" wrote:

Hi Mike,

Thanks for reply and assistance.

Does your solution take into account Gary's Student Post:

If A13 and B13 have values, C13 is empty, and D13 has a value,
then
do you want A13 thru B13 or A13 thru D13?


I would like A13 thru B13

Mike Fogleman wrote:
Is there other data surrounding this contiguous data that we need to
avoid?
If not, then this simple code will do it:


Sub test()
Dim LRow As Long

LRow = Cells(Rows.Count, 1).End(xlUp).Row
Rows(LRow).Copy Rows(LRow + 1)
End Sub

Mike F


Mike, will this code work with my request for A13 thru B13 based on
above,
selecting only contiguous data filled cells on that row?

Please advise.

Cheers,
Sam

--
Message posted via http://www.officekb.com




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default Copy and Paste LAST ROW of data

Hi Tom,

Thank you very much for reply and assistance.

Your code does the job Brilliantly!

However, could you adapt it to perform this routine on multiple worksheets
within the same workbook.

Further assistance very much appreciated.

Cheers
Sam

Tom Ogilvy wrote:

Sub CopyLast()
Dim r1 as Range, r2 as Range
set r1 = cells(rows.count,1).End(xlup)
if isempty(r1(1,2)) then
set r2 = r1
else
set r2 = r1.end(xltoRight)
end if
Range(r1,r2).Copy r1(2)
End Sub

--
Message posted via http://www.officekb.com

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Copy and Paste LAST ROW of data

This one does exclude any data on the last row that is to the right of a
blank cell. However, if there is data further down in column A after some
blank cells then this will find it and copy that row. More code would be
needed to avoid data that is below the contiguous data in column A.

Sub test()
Dim LRow As Long
Dim MyRng As Range

LRow = Cells(Rows.Count, 1).End(xlUp).Row
Set MyRng = Range("A" & LRow)
Range(MyRng, MyRng.End(xlToRight)).Copy Range("A" & LRow + 1)
End Sub

Mike F
"Sam via OfficeKB.com" <u4102@uwe wrote in message
news:77e9d5b8918b2@uwe...
Hi Mike,

Thanks for reply and assistance.

Does your solution take into account Gary's Student Post:

If A13 and B13 have values, C13 is empty, and D13 has a value,
then
do you want A13 thru B13 or A13 thru D13?


I would like A13 thru B13

Mike Fogleman wrote:
Is there other data surrounding this contiguous data that we need to
avoid?
If not, then this simple code will do it:


Sub test()
Dim LRow As Long

LRow = Cells(Rows.Count, 1).End(xlUp).Row
Rows(LRow).Copy Rows(LRow + 1)
End Sub

Mike F


Mike, will this code work with my request for A13 thru B13 based on
above,
selecting only contiguous data filled cells on that row?

Please advise.

Cheers,
Sam

--
Message posted via http://www.officekb.com



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default Copy and Paste LAST ROW of data

Hi Mike,

Thank you very much indeed for your time and assistance.

Your code works Great!

However, if there is data further down in column A after some
blank cells then this will find it and copy that row. More code would be
needed to avoid data that is below the contiguous data in column A.


Would it be possible for you to extend your Sub test() routine and provide
the additional code that would take the above scenario into account.

Much appreciated.

Cheers,
Sam

Mike Fogleman wrote:
This one does exclude any data on the last row that is to the right of a
blank cell. However, if there is data further down in column A after some
blank cells then this will find it and copy that row. More code would be
needed to avoid data that is below the contiguous data in column A.


Sub test()
Dim LRow As Long
Dim MyRng As Range


LRow = Cells(Rows.Count, 1).End(xlUp).Row
Set MyRng = Range("A" & LRow)
Range(MyRng, MyRng.End(xlToRight)).Copy Range("A" & LRow + 1)
End Sub


Mike F


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200709/1



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Copy and Paste LAST ROW of data

Sam, this will work to some extent if there is data below the target range,
it is also contiguous, and there is only one section of data. I have also
modified the code to run on each sheet in the workbook, as you requested of
Tom.
If there are several areas of data below the target data, then we will need
a way to differentiate among them to find the range.

Sub test()
Dim LRow As Long
Dim MyRng As Range
Dim i As Long
Dim ws As Worksheet

For Each ws In Worksheets
ws.Activate
LRow = Cells(Rows.Count, 1).End(xlUp).Row
Set MyRng = Range("A" & LRow)
i = MyRng.CurrentRegion.Rows.Count
i = LRow - i
If IsEmpty(Range("A" & i)) Then
i = i - 1
If i = 0 Then i = 1
Set MyRng = Range("A" & i)
Do While IsEmpty(MyRng)
i = i - 1
If i = 0 Then i = 1
Set MyRng = Range("A" & i)
If MyRng.Row = 1 Then
LRow = Cells(Rows.Count, 1).End(xlUp).Row
Set MyRng = Range("A" & LRow)
Exit Do
End If
Loop
LRow = MyRng.Row
Range(MyRng, MyRng.End(xlToRight)).Copy Range("A" & LRow + 1)
End If
Next
Worksheets(1).Activate
End Sub

Mike F
"Sam via OfficeKB.com" <u4102@uwe wrote in message
news:77ea6409c2360@uwe...
Hi Mike,

Thank you very much indeed for your time and assistance.

Your code works Great!

However, if there is data further down in column A after some
blank cells then this will find it and copy that row. More code would be
needed to avoid data that is below the contiguous data in column A.


Would it be possible for you to extend your Sub test() routine and provide
the additional code that would take the above scenario into account.

Much appreciated.

Cheers,
Sam

Mike Fogleman wrote:
This one does exclude any data on the last row that is to the right of a
blank cell. However, if there is data further down in column A after some
blank cells then this will find it and copy that row. More code would be
needed to avoid data that is below the contiguous data in column A.


Sub test()
Dim LRow As Long
Dim MyRng As Range


LRow = Cells(Rows.Count, 1).End(xlUp).Row
Set MyRng = Range("A" & LRow)
Range(MyRng, MyRng.End(xlToRight)).Copy Range("A" & LRow + 1)
End Sub


Mike F


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200709/1



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
How copy none excel data & paste in 2007 without overwriting data Wakefootin Excel Discussion (Misc queries) 2 October 8th 09 12:15 AM
Copy and paste - filtered data JLR-Mart Excel Discussion (Misc queries) 2 March 10th 08 09:46 AM
Copy and Paste data Michael M Excel Programming 7 November 10th 06 12:29 AM
filted data, copy and paste a col. puts data in wrong row how fix chris_fig New Users to Excel 1 October 16th 06 04:26 PM
Excel cut/Paste Problem: Year changes after data is copy and paste Asif Excel Discussion (Misc queries) 2 December 9th 05 05:16 PM


All times are GMT +1. The time now is 06:26 AM.

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

About Us

"It's about Microsoft Excel"