Insert Rows Macro
This may do what you describe, but I'm not sure it does what you want.
What happens when one of the quantities in column C is 1?
Option Explicit
Sub testme()
Dim iRow As Long
Dim HowMany As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim wks As Worksheet
Set wks = ActiveSheet
With wks
FirstRow = 2 'headers in row 1
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
For iRow = LastRow To FirstRow Step -1
HowMany = 0
With .Cells(iRow, "C")
If IsNumeric(.Value) Then
HowMany = .Value
End If
End With
If HowMany 0 Then
.Rows(iRow).Offset(1, 0).Resize(HowMany).Insert
.Cells(iRow, "A").Offset(1, 0).Resize(HowMany, 2).Value _
= .Cells(iRow, "A").Resize(1, 2).Value
.Cells(iRow, "C").Offset(1, 0).Resize(HowMany, 1).Value = 1
End If
Next iRow
End With
End Sub
A.S. wrote:
Hello,
I couldn't find a macro that does this, so if anyone can point me in the
right direction I would appreciate it:
Sample Data:
Product Code Qty
ABCD AXD 2
DJFL DFY 3
Basically I want the macro to look at the quantity and recognize 2 and then
insert 2 rows after ABCD, where the ABCD & AXD would be copied and the number
1 entered in the Qty for all the rows. So basically, data would then look
like:
Product Code Qty
ABCD AXD 2
ABCD AXD 1
ABCD AXD 1
DJFL DFY 3
DJFL DFY 1
DJFL DFY 1
DJFL DFY 1
Thanks.
--
Dave Peterson
|