Hi All,
This is my first post so go easy on me, also let me know if I am posting wrong.
I found an old thread relating to this topic that included a code however there is one change that I would like to make and my coding knowledge isn't advanced enough to figure it out.
I am trying to have a code that looks at a column, in this case column C, and if the value in a cell is, for example, '2' a new blank row gets inserted either above or below and the contents of the entire row gets copied into the new blank row giving me two identical rows, matching value in column C.
The below code does almost exactly what i need but it makes the same number of new rows with the same data as the value that appears in column C.
What i would like to do is alter the code so that I end up with a total number of rows with the same data as the value that appears in collumn C.
Sub Inert_rows_v2()
Dim r As Long
Application.ScreenUpdating = False
For r = Range("A" & Rows.Count).End(xlDown).Row To 1 Step -1
With Cells(r, 3)
If IsNumeric(.Value) And Not IsEmpty(.Value) Then
Rows(r + 1).Resize(.Value).Insert
Range(Replace("A#:BW#", "#", r)).Copy
Range("A" & r + 1).Resize(.Value).PasteSpecial Paste:=xlPasteValues
Range("A" & r + 1).Resize(.Value).PasteSpecial Paste:=xlPasteFormats
End If
End With
Next r
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
I have attached a before and after image of what I am trying to acheive.
I hope this makes some sense.
Thanks in advance
This is my first post so go easy on me, also let me know if I am posting wrong.
I found an old thread relating to this topic that included a code however there is one change that I would like to make and my coding knowledge isn't advanced enough to figure it out.
I am trying to have a code that looks at a column, in this case column C, and if the value in a cell is, for example, '2' a new blank row gets inserted either above or below and the contents of the entire row gets copied into the new blank row giving me two identical rows, matching value in column C.
The below code does almost exactly what i need but it makes the same number of new rows with the same data as the value that appears in column C.
What i would like to do is alter the code so that I end up with a total number of rows with the same data as the value that appears in collumn C.
Sub Inert_rows_v2()
Dim r As Long
Application.ScreenUpdating = False
For r = Range("A" & Rows.Count).End(xlDown).Row To 1 Step -1
With Cells(r, 3)
If IsNumeric(.Value) And Not IsEmpty(.Value) Then
Rows(r + 1).Resize(.Value).Insert
Range(Replace("A#:BW#", "#", r)).Copy
Range("A" & r + 1).Resize(.Value).PasteSpecial Paste:=xlPasteValues
Range("A" & r + 1).Resize(.Value).PasteSpecial Paste:=xlPasteFormats
End If
End With
Next r
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
I have attached a before and after image of what I am trying to acheive.
I hope this makes some sense.
Thanks in advance