insert row macro

C

calebmichaud

I am trying to add lines to subcategories. Lets say there is
Dog
-pug
-retriever
-shitzu

Cat
-hairy
-smooth
-fiesty

Dog and Cat are in column e while the subs are in colum f
so it actually looks on the spreadsheet like
Dog Pug
Dog Retriever
Dog Shitzu
Cat Hairt
ETC

I want to be able to add a line to the last entry of each sub
category. I am having a tough time figuring out the code as i havent
worked with macros in excel. right now i have a line insertion macro,
but it inserts it at the same place every time....meaning it starts
inserting it in the middle of the grouping after a while. how can i
have excel search for last entry of Dog in a column and then insert a
line below this...keeping the formulas. I would need another button
for cat...and then for my other categories. Here is my current code.

Rows("18:18").Select
Selection.Insert Shift:=xlDown
Range("F18").Select\

Any help would be much appreciated. i am trying to knock the socks off
my bosses.

Caleb
 
G

gaba53

I am trying to add lines to subcategories. Lets say there is
Dog
-pug
-retriever
-shitzu

Cat
-hairy
-smooth
-fiesty

Dog and Cat are in column e while the subs are in colum f
so it actually looks on the spreadsheet like
Dog Pug
Dog Retriever
Dog Shitzu
Cat Hairt
ETC

I want to be able to add a line to the last entry of each sub
category. I am having a tough time figuring out the code as i havent
worked with macros in excel. right now i have a line insertion macro,
but it inserts it at the same place every time....meaning it starts
inserting it in the middle of the grouping after a while. how can i
have excel search for last entry of Dog in a column and then insert a
line below this...keeping the formulas. I would need another button
for cat...and then for my other categories. Here is my current code.

Rows("18:18").Select
Selection.Insert Shift:=xlDown
Range("F18").Select\

Any help would be much appreciated. i am trying to knock the socks off
my bosses.

Caleb

I have done something similar to this. To create subtotal rows for
different types of jobs in a spreadsheet. I assume that this list will
be sorted first manually or through code. I will give you a rough
example of what might work.

Dim rowCount as int

rowCount = 1
do while Range("F"+cstr(rowCount)).Value <> ""
fColVal = Range("F" +cstr(rowCount)).value
x = fColVal
do while x = fColVal
rowCount = rowCount+1
Loop

****insert row however
****might need to index rowCounter
Loop
 

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