PC Review


Reply
Thread Tools Rate Thread

Copying a differing range of rows to a new worksheet

 
 
Andy Rigby
Guest
Posts: n/a
 
      23rd Mar 2009
I have a worksheet called "RawData" which has a continuous list of invoices,
I need to separate off the first invoice from the rest of the invoices into
a new worksheet and call it "sheet1". The number of rows from cell A1 at the
top left corner varies and is never constant from invoice to invoice however
the last row of the invoice I need to move always includes the text string
"NET PAYABLE TO". So I need to copy all rows from "A1" to the row that has
the text to a new worksheet called "sheet1", I then need to delete those
rows only from the original "RawData" worksheet, leaving the remaining
invoices in "RawData" intact. If it is helpful to you, the first row on
every invoice has the text string "TAX INVOICE"

Can this routine then be continued on all the other invoices in "RawData",
copying them to new worksheets in the same workbook "sheet2","sheet3" etc
until there is no data left in RawData, bearing in mind that there may be 10
invoices or 100 invoices in the "RawData" sheet.

I hope I explained this OK, I am only just dipping my toe in the water in
Excel programming and I am discovering that Excel can be amazingly
powerful....in the right hands, I think I am still wearing my kid gloves!!

Thanks for any assistance offered, I have spent hours looking at different
code examples on the net and attempting to make them work for me but to no
avail ;o(

Regards Andy
Cairns, Australia

 
Reply With Quote
 
 
 
 
jasontferrell
Guest
Posts: n/a
 
      23rd Mar 2009
There are some details I don't know, like the existence of blank rows
between invoices, but try this:

Public Function SeparateInvoices()
Dim shtRaw As Worksheet, shtInv As Worksheet
Dim lRow As Long, lCount As Long, lInitialRows As Long
Dim iSheet As Integer
Set shtRaw = Sheets("RawData")
lInitialRows = shtRaw.UsedRange.Rows.Count
iSheet = 1
Do While lCount < lInitialRows
lRow = 1
Do While Not InStr(1, shtRaw.Cells(lRow, 1).Value, "net
payable to", vbTextCompare) <> 0
lRow = lRow + 1
Loop
If lRow > 1 Then
Set shtInv = Sheets.Add
shtInv.Name = "Sheet" & iSheet
shtRaw.Range(shtRaw.Cells(1, 1).EntireRow, shtRaw.Cells
(lRow, 1).EntireRow).Copy shtInv.Range("A1")
shtRaw.Range(shtRaw.Cells(1, 1).EntireRow, shtRaw.Cells
(lRow, 1).EntireRow).Delete xlUp
End If
iSheet = iSheet + 1
lCount = lCount + lRow
Loop
Set shtInv = Nothing
Set shtRaw = Nothing
End Function
 
Reply With Quote
 
Andy Rigby
Guest
Posts: n/a
 
      24th Mar 2009
Hey, thanks Jason, I will give this a try when I get a moment, thanks for
your assistance.

Regards
Andy

"jasontferrell" <(E-Mail Removed)> wrote in message
news:ee03ba82-d601-4503-a2c3-(E-Mail Removed)...
> There are some details I don't know, like the existence of blank rows
> between invoices, but try this:
>
> Public Function SeparateInvoices()
> Dim shtRaw As Worksheet, shtInv As Worksheet
> Dim lRow As Long, lCount As Long, lInitialRows As Long
> Dim iSheet As Integer
> Set shtRaw = Sheets("RawData")
> lInitialRows = shtRaw.UsedRange.Rows.Count
> iSheet = 1
> Do While lCount < lInitialRows
> lRow = 1
> Do While Not InStr(1, shtRaw.Cells(lRow, 1).Value, "net
> payable to", vbTextCompare) <> 0
> lRow = lRow + 1
> Loop
> If lRow > 1 Then
> Set shtInv = Sheets.Add
> shtInv.Name = "Sheet" & iSheet
> shtRaw.Range(shtRaw.Cells(1, 1).EntireRow, shtRaw.Cells
> (lRow, 1).EntireRow).Copy shtInv.Range("A1")
> shtRaw.Range(shtRaw.Cells(1, 1).EntireRow, shtRaw.Cells
> (lRow, 1).EntireRow).Delete xlUp
> End If
> iSheet = iSheet + 1
> lCount = lCount + lRow
> Loop
> Set shtInv = Nothing
> Set shtRaw = Nothing
> End Function


 
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 into new worksheet PVANS Microsoft Excel Programming 2 31st Jul 2009 04:04 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 all Rows with data to a New worksheet VexedFist Microsoft Excel Programming 1 5th Oct 2006 09:00 PM
Problem copying rows to new worksheet caksey Microsoft Excel Programming 7 26th Feb 2004 03:11 PM
copying a range from another worksheet Haddock Microsoft Excel Worksheet Functions 2 21st Jan 2004 09:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:54 AM.