PC Review


Reply
Thread Tools Rate Thread

Copying selected rows into new worksheet

 
 
PVANS
Guest
Posts: n/a
 
      31st Jul 2009
Good afternoon everyone, hope someone can help me with this

I have a worksheet that has blocks of transactions, with a summary
transaction for each one at the bottom of the block, and blank rows
seperating the different blocks of trades.

The blocks are seperated by date and product
-----------------------------------------------------------------------------------------------
EG:
Date Quantity BUY/SELL Price Gross Sale Currency Account Item
20090727 16997 S 5 84985 GBP DEFAULT Coke
20090727 48606 S 5 243030 GBP DEFAULT Coke
20090727 10000 S 5 50000 GBP DEFAULT Coke
20090727 58316 S 4 233264 GBP DEFAULT Coke
20090727 133919 S 19 233264 GBP DEFAULT Coke

20090727 9238 S 5 46190 GBP DEFAULT Pepsi
20090727 4146 S 6 24876 GBP DEFAULT Pepsi
20090727 13384 S 11 24876 GBP DEFAULT Pepsi

etc.
------------------------------------------------------------------------------------------------
I am trying to write a macro that finds the final row of each transaction
(which is a summary of the rows above it) and copies it to a new worksheet.

Will provide further explanation if needed

Really appreciate any advice you can provide

Regards,
PVANS
 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      31st Jul 2009
Try the below macro..which will copy the row just before blank row to Sheet2.

Sub MyMacro()
Dim lngRow As Long, lngNRow As Long
Dim ws2 As Worksheet
Set ws2 = Sheets("Sheet2")
lngNRow = 1

For lngRow = 1 To Cells(Rows.Count, "A").End(xlUp).Row + 1
If Trim(Range("A" & lngRow)) = "" Then
Rows(lngRow - 1).Copy ws2.Rows(lngNRow)
lngNRow = lngNRow + 1
End If
Next
End Sub
--
If this post helps click Yes
---------------
Jacob Skaria


"PVANS" wrote:

> Good afternoon everyone, hope someone can help me with this
>
> I have a worksheet that has blocks of transactions, with a summary
> transaction for each one at the bottom of the block, and blank rows
> seperating the different blocks of trades.
>
> The blocks are seperated by date and product
> -----------------------------------------------------------------------------------------------
> EG:
> Date Quantity BUY/SELL Price Gross Sale Currency Account Item
> 20090727 16997 S 5 84985 GBP DEFAULT Coke
> 20090727 48606 S 5 243030 GBP DEFAULT Coke
> 20090727 10000 S 5 50000 GBP DEFAULT Coke
> 20090727 58316 S 4 233264 GBP DEFAULT Coke
> 20090727 133919 S 19 233264 GBP DEFAULT Coke
>
> 20090727 9238 S 5 46190 GBP DEFAULT Pepsi
> 20090727 4146 S 6 24876 GBP DEFAULT Pepsi
> 20090727 13384 S 11 24876 GBP DEFAULT Pepsi
>
> etc.
> ------------------------------------------------------------------------------------------------
> I am trying to write a macro that finds the final row of each transaction
> (which is a summary of the rows above it) and copies it to a new worksheet.
>
> Will provide further explanation if needed
>
> Really appreciate any advice you can provide
>
> Regards,
> PVANS

 
Reply With Quote
 
PVANS
Guest
Posts: n/a
 
      31st Jul 2009
thanks Jacob,

it worked like a charm

Have a good day

Regards,

"Jacob Skaria" wrote:

> Try the below macro..which will copy the row just before blank row to Sheet2.
>
> Sub MyMacro()
> Dim lngRow As Long, lngNRow As Long
> Dim ws2 As Worksheet
> Set ws2 = Sheets("Sheet2")
> lngNRow = 1
>
> For lngRow = 1 To Cells(Rows.Count, "A").End(xlUp).Row + 1
> If Trim(Range("A" & lngRow)) = "" Then
> Rows(lngRow - 1).Copy ws2.Rows(lngNRow)
> lngNRow = lngNRow + 1
> End If
> Next
> End Sub
> --
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "PVANS" wrote:
>
> > Good afternoon everyone, hope someone can help me with this
> >
> > I have a worksheet that has blocks of transactions, with a summary
> > transaction for each one at the bottom of the block, and blank rows
> > seperating the different blocks of trades.
> >
> > The blocks are seperated by date and product
> > -----------------------------------------------------------------------------------------------
> > EG:
> > Date Quantity BUY/SELL Price Gross Sale Currency Account Item
> > 20090727 16997 S 5 84985 GBP DEFAULT Coke
> > 20090727 48606 S 5 243030 GBP DEFAULT Coke
> > 20090727 10000 S 5 50000 GBP DEFAULT Coke
> > 20090727 58316 S 4 233264 GBP DEFAULT Coke
> > 20090727 133919 S 19 233264 GBP DEFAULT Coke
> >
> > 20090727 9238 S 5 46190 GBP DEFAULT Pepsi
> > 20090727 4146 S 6 24876 GBP DEFAULT Pepsi
> > 20090727 13384 S 11 24876 GBP DEFAULT Pepsi
> >
> > etc.
> > ------------------------------------------------------------------------------------------------
> > I am trying to write a macro that finds the final row of each transaction
> > (which is a summary of the rows above it) and copies it to a new worksheet.
> >
> > Will provide further explanation if needed
> >
> > Really appreciate any advice you can provide
> >
> > Regards,
> > PVANS

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying selected rows to a new workbook Jeffrey Marks Microsoft Excel New Users 0 27th Jul 2011 03:51 PM
Copying only selected items to another worksheet firewaterjoe Microsoft Excel Worksheet Functions 1 23rd Jan 2008 06:12 PM
Copying rows from worksheet A to worksheet B based on criteria =?Utf-8?B?am1tMDYyNg==?= Microsoft Excel Programming 2 11th Apr 2007 01:36 AM
Copying Selected Rows From Workbook1 to WorkBook2 seanswilson@gmail.com Microsoft Excel Misc 0 10th Oct 2006 11:27 PM
Copying selected rows to another sheet tacarme Microsoft Excel Worksheet Functions 3 25th Jun 2005 11:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:33 AM.