Macro to add Multiple rows in same sheet

N

ntwanano

Hi All,

I have been using the basic functions for excel for years now and have onlyrecently needed to work with Macros.

The basic use of the macro will be to add additional products onto an income statement.

For example: In a sheet i will have revenue for each of the individual products as well as costs for the individual products. What i am trying to do is to automatically add a new product into the income statement
I tried to record a macro but it will work in the first instance but the minute i add the second product it will work with the revenue but the costs are not in the same order. I think this is because it fixed the row where i enter the new row which is fine for the revenue as it is at the top but does not work with cost. Here is how is looks

Orginal:

A1:Revenue
A2: Apples
A3: Oranges
A4: Bananas
A5:Costs
A6: Apples
A7: Oranges
A8: Bananas

After running the macro I recorded i get

A1:Revenue
A2:pears
A3:Apples
A4: Oranges
A5: Bananas
A6:Costs
A7: Pears
A8: Apples
A9: Oranges
A10: Bananas


This is fine.

The problem occurs when i then add the second new product
A1:REVENUE
A2:paw Paw
A3:pears
A4:Apples
A5: Oranges
A6: Bananas
A7:paw Paw (this is supposed to be under costs)
A8:COSTS
A9: Pears
A10: Apples
A11: Oranges
A12: Bananas


As you can see once i add the second new product it gets inserted above costs and it should be below. So basically i need a evolving macro which is able to do this. Note that this is a basic example as i will be having different kind of costs for each of the products. For example cost will be spilt into fixed and variable costs and this is all calculated in one sheet

Your assistance will be appreaciated
 
G

GS

A couple of suggestions...

Show your code!

Is there some reason why your products must be duplicated in colA? Can
you not arrange them to have both a revenue col and a costs col? This
would make your task way much easier, I'd think!

Otherwise, if you insist on duplicating the products then define
dynamic ranges for Revenue and Costs so your code can ref each
respectively. This will need to be a complex definition for the
different sections so they don't include more than their own data, but
easily done just the same.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top