' add contingent values
For i = 1 To .UsedRange.Rows.Count
If .Cells(i, "B").Value = "contingent" Then
For x = 5 To 16
If IsNumeric(ws.Cells(i, x).Value) Then
sumMonths(x - 4) = sumMonths(x - 4) + ws.Cells(i, x).Value
End If
Next
End If
Next
' delete contingent
For i = ws.UsedRange.Rows.Count To 1 Step -1
If InStr(1, ws.Range("D" & i).Value, "Contingent", vbTextCompare) > 0 Then
ws.Cells(i, 1).EntireRow.Delete
End If
Next
' overwrite with just values
With .UsedRange
.Value = .Value
End With
' copy expenses to master temp
lr = mstTemp.Cells(.Rows.Count, "A").End(xlUp).Row + 1
mstTemp.Columns("A:A").NumberFormat = "@"
For i = 1 To .UsedRange.Rows.Count
If InStr(1, ws.Range("D" & i).Value, "Expense", vbTextCompare) > 0 And ws.Range("C" & i).Value <> "" _
And ws.Range("Q" & i).Value <> 0 Then
Set fillRangeRow = ws.Range(ws.Cells(i, 1), ws.Cells(i, 16))
Set rng = mstTemp.Cells(lr, 1)
Set rng = rng.Resize(1, fillRangeRow.Columns.Count)
rng.Value = fillRangeRow.Value
lr = lr + 1
End If
Next
' copy contingent to master file
With mstTemp
lr = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
.Range("A" & lr).Value = numericPart
.Range("C" & lr).Value = Contingent
.Range("D" & lr).Value = "Contingent"
For x = 1 To 12
.Cells(lr, x + 4).Value = sumMonths(x)
Next
End With
End With