adding row

M

massi

hi. i have a spread sheet where i have to record some events.
the first row is already formatted and the first cell has a number 1.
i would like a macro to automatically create another line each time a press
a button and that would increase the number of the first cell from the
previous line.

a sheet like below:

number header2 header3
1 bla bla zzz zzzz
2 qwfjkd jjioeereorko
3 gdfgfgf frefsdfdf

i would like a macro that associated to a button automatically add a line
below the last one, keeping the same formatting of the cells and in the line
added increase the column "number" by 1

in order to have:

number header2 header3
1 bla bla zzz zzzz
2 qwfjkd jjioeereorko
3 gdfgfgf frefsdfdf
4



thanks
 
J

Jacob Skaria

To add a row you can use this code; but if you are looking at auto numbering
you can acheive this with a simple formula in column A =IF(B2<>"",A1+1,"")

lngRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Rows(lngRow + 1).Insert
Cells(lngRow + 1, 1) = Cells(lngRow, 1) + 1


If this post helps click Yes
 
M

massi

thanks!

Jacob Skaria said:
To add a row you can use this code; but if you are looking at auto numbering
you can acheive this with a simple formula in column A =IF(B2<>"",A1+1,"")

lngRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Rows(lngRow + 1).Insert
Cells(lngRow + 1, 1) = Cells(lngRow, 1) + 1


If this post helps click Yes
 

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