PDA

View Full Version : [SOLVED:] Need help duplicating a row (if not already duplicated)



louise1
08-20-2017, 02:18 AM
Hi everyone,

I'm puzzled by this problem and hoping someone can help.

I have a large file of data. In some of the lists ‘Settings’ is listed twice and sometimes Settings is listed once.
In a Macro, is there any way off adding an extra row below beneath ‘Settings’, if it’s not already duplicated. (It would be great if this extra row could include the word Settings)

A few screenshots are below for my example.

20121
It would be great if the above data, could look like
20122

If anyone can help that would be amazing, Thanks!

p45cal
08-20-2017, 02:37 AM
Try:
Sub blah()
For i = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
With Cells(i, 1)
If .Value = "Settings:" Then
If .Offset(-1) <> "Settings:" And .Offset(1) <> "Settings:" Then
.Offset(1).EntireRow.Insert
.Offset(1).Value = "Settings:"
End If
End If
End With
Next i
End Sub
Not the fastest code, but if you don't have to do this too often it should do.
It works on the active sheet.

louise1
08-20-2017, 07:51 AM
That worked perfectly.
Thank you so much for your help, it was exactly what I needed.