ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   how do i count and insert rows (https://www.excelbanter.com/excel-discussion-misc-queries/230748-how-do-i-count-insert-rows.html)

Calvin

how do i count and insert rows
 
I have Names begining with the letter C (c1205, c4356, c8609) i need 6 rows
between every name, the data i import dosent always follow this rule so i
need to insert the number of missing rows and also add a 0 to the rows i
insert.

Mike H

how do i count and insert rows
 
Hi,

I don't understand the second part of the question and possibly not even the
first part but this small macro inserts 6 rows between each value in column
A. Change MC to your column

Sub Insert_Rows()
mc = "A"
For i = Cells(Rows.Count, mc).End(xlUp).Row To 2 Step -1
Rows(i).Resize(6).Insert
Next i
End Sub


Mike

"calvin" wrote:

I have Names begining with the letter C (c1205, c4356, c8609) i need 6 rows
between every name, the data i import dosent always follow this rule so i
need to insert the number of missing rows and also add a 0 to the rows i
insert.


Simon Lloyd[_226_]

how do i count and insert rows
 

calvin;344314 Wrote:
I have Names begining with the letter C (c1205, c4356, c8609) i need 6
rows
between every name, the data i import dosent always follow this rule so
i
need to insert the number of missing rows and also add a 0 to the rows
i
insert.I would need some dummy data/workbook to workout the counting missing

rows, however this code will insert 6 rows for each instance and add
zero.


Code:
--------------------
Sub Insert_6_rows_add_0()
Dim i As Long
For i = Range("A" & Rows.Count).End(xlUp).Row To 7 Step -1
Rows(i & ":" & i - 5).EntireRow.Insert
Range("A" & i & ":A" & i - 5).Value = 0
Next i
End Sub
--------------------


--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=96336


Calvin

how do i count and insert rows
 
Not quite what i am looking for lets try it again
my data is as follows
Ctu25 (names)
18
15
23
24
16
18
Ctu26 (names)
22
21
20
15
17
ctu32(names)
21
24
32
32
21
13

i need to count the rows between the names if it is 6 rows do nothing if not
add the missing rows and a zero as a place holder
6 rows between every name the data sometimes give me 3 or 5

"Simon Lloyd" wrote:


calvin;344314 Wrote:
I have Names begining with the letter C (c1205, c4356, c8609) i need 6
rows
between every name, the data i import dosent always follow this rule so
i
need to insert the number of missing rows and also add a 0 to the rows
i
insert.I would need some dummy data/workbook to workout the counting missing

rows, however this code will insert 6 rows for each instance and add
zero.


Code:
--------------------
Sub Insert_6_rows_add_0()
Dim i As Long
For i = Range("A" & Rows.Count).End(xlUp).Row To 7 Step -1
Rows(i & ":" & i - 5).EntireRow.Insert
Range("A" & i & ":A" & i - 5).Value = 0
Next i
End Sub
--------------------


--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=96336




All times are GMT +1. The time now is 01:25 PM.

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