Writing a macro

  • Thread starter Thread starter Roxio
  • Start date Start date
R

Roxio

I need to write a macro that will allow me to add any number of rows (as
desired) BETWEEN each of the existing values in column A. Now when this
is done, it must at the same time populate these new rows with with cell
values above the inserted rows.

So if A1 = Apples... and I add 5 rows,only the cells inserted in col A
below A1 should take the value "Apples" until the next value Pears.
Then the next 5 cells below Pears should have "Pears".

Hope this is explained clearly.

Thanx
Roxio
 
One way

Sub addrowsandfill()
For i = Cells(Rows.Count, "a").End(xlUp).Row To 12 Step -1
x = Cells(i, 1)
If Cells(i, 1) <> Cells(i - 1, 1) Then
Cells(i, 1).Resize(4).EntireRow.Insert
Cells(i, 1).Resize(5).Value = x
End If
Next
End Sub
 

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

Back
Top