PC Review


Reply
Thread Tools Rate Thread

copy rows based on conditions and insert them into another sheet...

 
 
bramnizzle@gmail.com
Guest
Posts: n/a
 
      25th Nov 2007
Here's a new one...

I have an accounting workbook with some hidden sheets based on months.
All month sheets have a Fixed heading with some accounting information
below it and further down the sheet, a Unpaid From Last Month heading
with some information. What I need is that if there are lines under
the Fixed heading that have negative balances, I want that entire row
inserted under the Unpaid From Last Month.

For example...

within the "November" worksheet...

A B C
D ... L
9 Fixed
10 Bill Frequency
Amount Yet To Pay
11 ( blank
cells )
12 Account
1
(4100.00)
13 Account
2
3300.00
14 Account
3
(4333.00)
15
16
17
18
19
20
21
22
23 Unpaid From Last Month
24 ( blank
cells )
25



On "December"...

Rows 12 and 14 should be copied from "November" and placed in
"December" under Unpaid From Last Month.

The problem I'm having is that for "December" 'Unpaid From Last Month'
might start on row 21 or 20. And for any given month, there might be
a lot more accounts than accoutn 1, 2, or 3.

So basically, the user clicks a button to create a new month sheet
will be placed at the very end. I need the macro to access the
previous sheet (which should be the previous month), search the rows
only under the "Fixed" heading (which could be any number of rows) and
find a negative number in column L. If there is a negative number,
copy that entire row and place it on the new sheet under the heading
"Unpaid From Last Month".

I'm envisioning loops, but I'm still very new to Excel VBA. Any help
would be greatly appreciated.
 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      25th Nov 2007
Look in the vba help index for FINDNEXT. There is a good example. After the
find you will want to copy to the next available row in the destination
sheet. You can use something like:

lastrow=cells(rows.count, "a").end(xlup).row+1
c.entirerow.copy cells(lastrow,"a")

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
<(E-Mail Removed)> wrote in message
news:0ab100b1-5b27-4438-92c2-(E-Mail Removed)...
> Here's a new one...
>
> I have an accounting workbook with some hidden sheets based on months.
> All month sheets have a Fixed heading with some accounting information
> below it and further down the sheet, a Unpaid From Last Month heading
> with some information. What I need is that if there are lines under
> the Fixed heading that have negative balances, I want that entire row
> inserted under the Unpaid From Last Month.
>
> For example...
>
> within the "November" worksheet...
>
> A B C
> D ... L
> 9 Fixed
> 10 Bill Frequency
> Amount Yet To Pay
> 11 ( blank
> cells )
> 12 Account
> 1
> (4100.00)
> 13 Account
> 2
> 3300.00
> 14 Account
> 3
> (4333.00)
> 15
> 16
> 17
> 18
> 19
> 20
> 21
> 22
> 23 Unpaid From Last Month
> 24 ( blank
> cells )
> 25
>
>
>
> On "December"...
>
> Rows 12 and 14 should be copied from "November" and placed in
> "December" under Unpaid From Last Month.
>
> The problem I'm having is that for "December" 'Unpaid From Last Month'
> might start on row 21 or 20. And for any given month, there might be
> a lot more accounts than accoutn 1, 2, or 3.
>
> So basically, the user clicks a button to create a new month sheet
> will be placed at the very end. I need the macro to access the
> previous sheet (which should be the previous month), search the rows
> only under the "Fixed" heading (which could be any number of rows) and
> find a negative number in column L. If there is a negative number,
> copy that entire row and place it on the new sheet under the heading
> "Unpaid From Last Month".
>
> I'm envisioning loops, but I'm still very new to Excel VBA. Any help
> would be greatly appreciated.


 
Reply With Quote
 
bramnizzle@gmail.com
Guest
Posts: n/a
 
      25th Nov 2007
in your line of code
lastrow=cells(rows.count, "a").end(xlup).row+1

what does "a" represent? The column A? or some text I'm supposed to
enter?
 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      25th Nov 2007
goto a vba module>type cells>touch f1 key

Cells Property
See AlsoApplies ToExampleSpecifics
Cells Property as it applies to the Application object.

Returns a Range object that represents all the cells on the active
worksheet. If the active document isn't a worksheet, this property fails.
Read-only.

expression.Cells

expression Required. An expression that returns an Application object.

Cells Property as it applies to the Range object.

Returns a Range object that represents the cells in the specified range.
Read-only.

expression.Cells

expression Required. An expression that returns a Range object.

Cells Property as it applies to the Worksheet object.

Returns a Range object that represents all the cells on the worksheet (not
just the cells that are currently in use). Read-only.

expression.Cells

expression Required. An expression that returns a Worksheet object.

Remarks
Because the Item property is the default property for the Range object, you
can specify the row and column index immediately after the Cells keyword.
For more information, see the Item property and the examples for this topic.

Using this property without an object qualifier returns a Range object that
represents all the cells on the active worksheet.

Example
This example sets the font size for cell C5 on Sheet1 to 14 points.

Worksheets("Sheet1").Cells(5, 3).Font.Size = 14
This example clears the formula in cell one on Sheet1.

Worksheets("Sheet1").Cells(1).ClearContents
-- Don GuillettMicrosoft MVP ExcelSalesAid
(E-Mail Removed)<(E-Mail Removed)> wrote in message
news:0088cce5-c0d4-497b-9d16-(E-Mail Removed)...
> in your line of code
> lastrow=cells(rows.count, "a").end(xlup).row+1
>
> what does "a" represent? The column A? or some text I'm supposed to
> enter?


 
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
copy rows from one Data sheet to another sheet based on cell conte John McKeon Microsoft Excel Misc 2 15th May 2010 06:49 AM
Search for rows in one sheet and copy into another sheet based on customer id chitiksha@gmail.com Microsoft Excel Worksheet Functions 1 22nd Oct 2007 03:09 AM
Help: auto-copy entire rows from 1 sheet (based on cell criteria) to another sheet. bertbarndoor Microsoft Excel Programming 4 5th Oct 2007 04:00 PM
Copy rows from one sheet to another based on a cell value =?Utf-8?B?U00x?= Microsoft Excel Worksheet Functions 1 21st Dec 2006 01:01 AM
Re: Copy rows from one sheet to another based on a cell value =?Utf-8?B?TWF4?= Microsoft Excel New Users 0 21st Dec 2006 01:00 AM


Features
 

Advertising
 

Newsgroups
 


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