Macro insert rows depending on # in Column B
Hi
Assuming your data starts in cell A1 then this should do
Sub tester()
Dim TargetRange As Range
Dim TempValue As Integer, i As Integer, j As Integer
Set TargetRange = Range("A1").CurrentRegion
With TargetRange
For i = .Rows.Count To 1 Step -1
TempValue = .Cells(i, 2).Value
If TempValue 0 Then
For j = 1 To TempValue
.Rows(i + 1).Insert Shift:=xlDown
Next j
End If
Next i
End With
Set TargetRange = Nothing
End Sub
As with any sub that changes a Range, you start from the bottom and
work your way up to insert rows
regards
Paul
On Apr 16, 3:59*am, Splendalisa
wrote:
HI,
I have this spreadsheet named Test and the # for the number of rows I want
inserted below this line is in Column B. Can you tell me the VBA to get this
done?
Here is example:
A * * * B
;laskdjf;alskdjf;lskj *
lskdjf;lskdfj;alskj * *
laskjf;sldfksj *
a;sldkfjds;l * *4
lskdjf;lskdjf;slk * * *
alsdkjf;alsdkfj
lasdjfs;ldfkj * 3
a;sldkfjs;lkfj *
;alsdkjf;alskdfj * * * *
;alsdkfja;sdkflj * * * *
a;lskdjf;lsadkf 3
a;sldkfj;asdlkfj * * * *
;alskfjdf;alskj
l;aksdjf;alsdkjf * * * *2
--
Splendalisa
|