ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   insert rows (https://www.excelbanter.com/excel-programming/293179-insert-rows.html)

dave!!

insert rows
 
i have several columns of information, one of them being "claim number" and
another being "report number" (report numbers are 1 through 5...there is
always at least a 1, or maybe 1 and 2...etc) I need to have 5 instances of
each claim number. What code could i use so that it would look at the
report number and if its a "1" then look at the next line and if that is
also a "1" insert 4 rows below it, if the report number is a "1" and next
line is a "2" then insert 3 rows below it...etc. Basically I want the macro
to scan the column and each time there is a "1" to look at the previous line
to get report value "x", get the report number and insert 5-x rows below it.

if anyone needs clarification let me know.

Thanks,
Dave



Tom Ogilvy

insert rows
 
Sub AddLines()
Dim rng As Range
Dim i As Long
Dim num As Long
Set rng = Cells(Rows.Count, 1).End(xlUp)

For i = rng.Row To 2 Step -1
If Cells(i + 1, 1).Value < Cells(i, 1).Value And _
Cells(i + 1, 1) < "" Then
num = 5 - Cells(i, 2).Value
If num 0 Then
Cells(i + 1, 1).Resize(num).EntireRow.Insert
End If
End If
Next

End Sub


Might be what you want.

Test on a copy of your data.

--
Regards,
Tom Ogilvy



"dave!!" wrote in message
...
i have several columns of information, one of them being "claim number"

and
another being "report number" (report numbers are 1 through 5...there is
always at least a 1, or maybe 1 and 2...etc) I need to have 5 instances

of
each claim number. What code could i use so that it would look at the
report number and if its a "1" then look at the next line and if that is
also a "1" insert 4 rows below it, if the report number is a "1" and next
line is a "2" then insert 3 rows below it...etc. Basically I want the

macro
to scan the column and each time there is a "1" to look at the previous

line
to get report value "x", get the report number and insert 5-x rows below

it.

if anyone needs clarification let me know.

Thanks,
Dave






All times are GMT +1. The time now is 02:22 PM.

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