Sub xmas()
Dim LstRw As Long, xRow As Long
LstRw = Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
For xRow = LstRw To 2 Step -1
Cells(xRow, 1).Offset(1).EntireRow.Resize(Cells(xRow, 1).Offset(, 1).Value - 1).Insert
Cells(xRow, 1).AutoFill Cells(xRow, 1).Resize(Cells(xRow, 1).Offset(, 1).Value), Type:=xlFillSeries
Next
Application.ScreenUpdating = True
End Sub
Probably much better ways of achieving this but try...
Rich (BB code):Sub xmas() Dim LstRw As Long, xRow As Long LstRw = Range("A" & Rows.Count).End(xlUp).Row Application.ScreenUpdating = False For xRow = LstRw To 2 Step -1 Cells(xRow, 1).Offset(1).EntireRow.Resize(Cells(xRow, 1).Offset(, 1).Value - 1).Insert Cells(xRow, 1).AutoFill Cells(xRow, 1).Resize(Cells(xRow, 1).Offset(, 1).Value), Type:=xlFillSeries Next Application.ScreenUpdating = True End Sub
Don't be modest..It works..Except if value in B is 1.
Any idea..
Sub xmas2()
Dim LstRw As Long, xRow As Long
LstRw = Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
For xRow = LstRw To 2 Step -1
If Cells(xRow, 1).Offset(, 1).Value <> 1 Then
Cells(xRow, 1).Offset(1).EntireRow.Resize(Cells(xRow, 1).Offset(, 1).Value - 1).Insert
Cells(xRow, 1).AutoFill Cells(xRow, 1).Resize(Cells(xRow, 1).Offset(, 1).Value), Type:=xlFillSeries
End If
Next
Application.ScreenUpdating = True
End Sub
Nothing to do with modesty, just should be a better way code below will deal with the 1 situation
Rich (BB code):Sub xmas2() Dim LstRw As Long, xRow As Long LstRw = Range("A" & Rows.Count).End(xlUp).Row Application.ScreenUpdating = False For xRow = LstRw To 2 Step -1 If Cells(xRow, 1).Offset(, 1).Value <> 1 Then Cells(xRow, 1).Offset(1).EntireRow.Resize(Cells(xRow, 1).Offset(, 1).Value - 1).Insert Cells(xRow, 1).AutoFill Cells(xRow, 1).Resize(Cells(xRow, 1).Offset(, 1).Value), Type:=xlFillSeries End If Next Application.ScreenUpdating = True End Sub
Cells(xRow,[COLOR="#FF0000"][B]"A"[/B][/COLOR])
Sub xmas2()
Dim LstRw As Long, xRow As Long
LstRw = Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
For xRow = LstRw To 2 Step -1
If Cells(xRow, [COLOR="#FF0000"][B]1[/B][/COLOR]).Offset(, [COLOR="#0000CD"][B]1[/B][/COLOR]).Value <> 1 Then
Cells(xRow, [COLOR="#FF0000"][B]1[/B][/COLOR]).Offset(1).EntireRow.Resize(Cells(xRow, [COLOR="#FF0000"][B]1[/B][/COLOR]).Offset(, [COLOR="#0000CD"][B]1[/B][/COLOR]).Value - 1).Insert
Cells(xRow, [COLOR="#FF0000"][B]1[/B][/COLOR]).AutoFill Cells(xRow, [COLOR="#FF0000"][B]1[/B][/COLOR]).Resize(Cells(xRow, [COLOR="#FF0000"][B]1[/B][/COLOR]).Offset(, [COLOR="#0000CD"][COLOR="#0000CD"][B]1[/B][/COLOR][/COLOR]).Value), Type:=xlFillSeries
End If
Next
Application.ScreenUpdating = True
End Sub
LstRw = Range("A" & Rows.Count).End(xlUp).Row
Sub xmas2()
Dim LstRw As Long, xRow As Long
LstRw = Range("B" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
For xRow = LstRw To 2 Step -1
If Cells(xRow, "B").Offset(, 2).Value <> 1 Then
Cells(xRow, "B").Offset(1).EntireRow.Resize(Cells(xRow, "B").Offset(, 2).Value - 1).Insert
Cells(xRow, "B").AutoFill Cells(xRow, "B").Resize(Cells(xRow, "B").Offset(, 2).Value), Type:=xlFillSeries
End If
Next
Application.ScreenUpdating = True
End Sub
in the code below the red 1's are the column references (which i could/should have written aswhich you probably would have understood better) so you make the 1 either 2 or "b" for the "sn" column if you wanted it to be column b.Rich (BB code):cells(xrow,"a")
The blue 1 is how many columns to the right the "qtty" column is compared to the "sn" column.
So for instance if your "sn" column was a and you wanted column c you would change it to a 2
Rich (BB code):sub xmas2() dim lstrw as long, xrow as long lstrw = range("a" & rows.count).end(xlup).row application.screenupdating = false for xrow = lstrw to 2 step -1 if cells(xrow, 1).offset(, 1).value <> 1 then cells(xrow, 1).offset(1).entirerow.resize(cells(xrow, 1).offset(, 1).value - 1).insert cells(xrow, 1).autofill cells(xrow, 1).resize(cells(xrow, 1).offset(, 1).value), type:=xlfillseries end if next application.screenupdating = true end sub
the "a" in the line below needs changing to whatever the "sn" column is
Rich (BB code):lstrw = range("a" & rows.count).end(xlup).row
so finally with "sn" being column "b" and "qtty" being column d you would get...
Rich (BB code):sub xmas2() dim lstrw as long, xrow as long lstrw = range("b" & rows.count).end(xlup).row application.screenupdating = false for xrow = lstrw to 2 step -1 if cells(xrow, "b").offset(, 2).value <> 1 then cells(xrow, "b").offset(1).entirerow.resize(cells(xrow, "b").offset(, 2).value - 1).insert cells(xrow, "b").autofill cells(xrow, "b").resize(cells(xrow, "b").offset(, 2).value), type:=xlfillseries end if next application.screenupdating = true end sub