Macro - insert row

W

wilga24

I have a spreadsheet that includes a column of names
(Column K). I wish to enter in a blank row everytime that
the name in column k changes.

I have set up a macro as follows: -

Sub Macro3()
Selection. EntireRow.insert
End sub

What I want to so is somehow run this macro everytime the
name in column K is not the same as the cell above, ie if
k5 does not = k4.

Is there a control button process that I can use so that
when I click the button the macro will run through column
K and insert a row everytime the name changes.

I also thought maybe I can paste a formula in another
column along the lines of: -

=if(k5=k4,"x",!run macro3!)

its what goes in place of !run macro3! that baffles me.

Can anyone suggest a solution. The manual way of insert
the row will mean many hours work.

Regards

George Watson
 
S

steve smallman

Try


Sub Macro3()
Range("K1").select
do until activecell.value=""
If activecell.value=activecell.offset(1,0).value then
selection.offset(1,0).select
else
Selection. EntireRow.insert
selection.offset(2,0).select
end if
loop
End sub


untested - so you may need to step through the macro to
see if/where it goes wrong.

Steve
 

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