ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Writing a macro (https://www.excelbanter.com/excel-programming/343896-writing-macro.html)

Roxio

Writing a macro
 

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


--
Roxio
------------------------------------------------------------------------
Roxio's Profile: http://www.excelforum.com/member.php...o&userid=28366
View this thread: http://www.excelforum.com/showthread...hreadid=479478


Don Guillett[_4_]

Writing a macro
 
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


--
Don Guillett
SalesAid Software

"Roxio" wrote in
message ...

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


--
Roxio
------------------------------------------------------------------------
Roxio's Profile:

http://www.excelforum.com/member.php...o&userid=28366
View this thread: http://www.excelforum.com/showthread...hreadid=479478





All times are GMT +1. The time now is 02:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com