I have a table that I want to add "TOTAL" rows for two rows down from any instance of "SUBCONTRACT". I have the following code but it just keeps going to the first instance of "SUBCONTRACT" and keeps adding a TOTAL row only for the first instance of SUBCONTRACT. I would like it to continue down the column and add the TOTAL row for each instance of SUBCONTRACT, not just the first one. Any help would be appreciated.
VBA Code:
Sub Ttl_Row()
'**********Move the ttCatSum values to the proper columns
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
' Set the worksheet where your data is located
Set ws = ThisWorkbook.Sheets("Job Cost Analysis Report")
' Find the last row with data in column A
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
' Loop through each row until the last row with data
For i = 1 To lastRow
'Find 1 in Job Column
Dim ing As Range
Dim str As String
Set ing = Sheets("Job Cost Analysis Report").Range("TBL_JCAR[Description]").Find("SUBCONTRACT", LookIn:=xlValues, LookAt:=xlWhole, SearchDirection:=xlNext)
'If Not rng Is Nothing Then
On Error GoTo NextStep
str = ing.Address
Range(str).Select
'End If
'Insert Total Row
ActiveCell.Offset(2, 0).EntireRow.Insert
ActiveCell.Offset(2, 0).Select
ActiveCell.Value = "TOTAL"
' Intersect(ActiveCell.EntireRow, ActiveCell.CurrentRegion).Font.Bold = True
Next i
NextStep:
Range("TBL_JCAR[[#Headers],[Job]]").Offset(1, 0).Select
End Sub
Last edited by a moderator: