sspatriots
Well-known Member
- Joined
- Nov 22, 2011
- Messages
- 565
- Office Version
- 365
- Platform
- Windows
Good morning,
I'm trying to use the code below that I found to insert a new row in a table just below the last occurrence of finding "1 AJW" in column C. This code I copied and tried to manipulate was originally set up up to insert two rows. I only need to insert 1 row. I also don't quite get what the ".Value" and ".Offset" are doing in the code or how to adjust for my situation.
Sub InsertNewJob
Dim Lst As Integer, n As Long, Txt As String, Temp As String, R As Range
Lst = Range("C" & Rows.Count).End(xlUp).Row
For n = Lst To 2 Step -1
With Range("C" & n)
Txt = ""
Select Case True
Case Left(.Value, 2) & .Offset(, 5).Value = "1 AJW"
If IsNumeric(Mid(.Value, 3, 1)) Then
Txt = "1 AJW"
End If
Case Left(.Value, 3) & .Offset(, 5).Value = "1 AJW"
End Select
If Not Txt = Temp Then
.Offset(1).Resize(2).EntireRow.Insert
Temp = Txt
End If
End With
End Sub
Thanks, SS
I'm trying to use the code below that I found to insert a new row in a table just below the last occurrence of finding "1 AJW" in column C. This code I copied and tried to manipulate was originally set up up to insert two rows. I only need to insert 1 row. I also don't quite get what the ".Value" and ".Offset" are doing in the code or how to adjust for my situation.
Sub InsertNewJob
Dim Lst As Integer, n As Long, Txt As String, Temp As String, R As Range
Lst = Range("C" & Rows.Count).End(xlUp).Row
For n = Lst To 2 Step -1
With Range("C" & n)
Txt = ""
Select Case True
Case Left(.Value, 2) & .Offset(, 5).Value = "1 AJW"
If IsNumeric(Mid(.Value, 3, 1)) Then
Txt = "1 AJW"
End If
Case Left(.Value, 3) & .Offset(, 5).Value = "1 AJW"
End Select
If Not Txt = Temp Then
.Offset(1).Resize(2).EntireRow.Insert
Temp = Txt
End If
End With
End Sub
Thanks, SS