Help inserting row when condition is met

Closed
Stephanie - Jan 5, 2011 at 04:31 PM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Jan 6, 2011 at 10:41 AM
Hello,

I am trying to write a macro that would insert a row when the cell contains either, "Total", "Male" or "White". There are 3 sets of "Total", "Male" or "White" in each section of data.

All of the data is in Column "C".

This code works, EXCEPT for some reason it is not working correctly in the last section of data (last 39 rows of my data), and is not consistent with the way it is not working. In the first set, it is inserting a row above "Total" and "Male".
In the second set, it is inserting a row above "Total" and "Male".
In the third set, it is inserting a row above "Total" only.

This is the code:

Sub InsKeyWord()
Dim i As Long
Dim LastRow As Long
Dim Arr As Variant
LastRow = Cells(Rows.Count, "C").End(xlUp).Row
Arr = Array("Total", "Male", "White")
For x = 0 To UBound(Arr)
For i = LastRow To 2 Step -1
With Cells(i, "C")
If .Value Like Arr(x) Then
.Resize(1, 1).EntireRow.Insert
End If
End With
Next i
Next x

End Sub


Please help! Thanks!

Related:

1 response

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 555
Jan 6, 2011 at 10:41 AM
Hi Stephanie,

Have you checked your capitols; "Total" is not the same as "total".

Best regards,
Trowa
0