I need add a row under any row that contains certain keywords, based on these keywords, the new row will be populated with different values.
(note: value in column A and B always copies from the row above)
column E contains "4'dia" and "Invert", column N does not contain "Toho", the new row should look like below:
column E contains "5'dia" and "Invert", column N does not contain "Toho", the new row should look like below:
column E contains "4'dia" and "Invert", column N contains "Toho", the new row should look like below:
The first part is working like a charm, no issues at all, but the "5'dia", and the '4'dia" with "Toho" are not adding a row to the excel file at all, any ideas?
(All the files used for testing do contain the proper keywords) any help is appreciated
code posted below
(note: value in column A and B always copies from the row above)
column E contains "4'dia" and "Invert", column N does not contain "Toho", the new row should look like below:
column E contains "5'dia" and "Invert", column N does not contain "Toho", the new row should look like below:
column E contains "4'dia" and "Invert", column N contains "Toho", the new row should look like below:
The first part is working like a charm, no issues at all, but the "5'dia", and the '4'dia" with "Toho" are not adding a row to the excel file at all, any ideas?
(All the files used for testing do contain the proper keywords) any help is appreciated
code posted below
VBA Code:
Public rng2 As Range, lr4 As Long, i As Long
Sub Flowline()
Set rng2 = Range("A1").CurrentRegion
lr4 = rng2.Cells(Rows.Count, "K").End(3).Row
For i = lr4 To 2 Step -1
If rng2.Cells(i, 11) Like "*4'dia**Invert*" And _ 'THIS PART IS WORKING JUST FINE
Not rng2.Cells(i, 14) Like "*Toho*" Then
rng2.Cells(i, 11).Offset(1).EntireRow.Insert
rng2.Cells(i, 3).Offset(1).Resize(1, 9).Value = _
Array("1", "F14050J", "Yes", "", "", "185", "Production", "500", "FLOWLINE,4' Diameter")
rng2.Cells(i, 1).Offset(1).Resize(1, 2).Value = rng2.Cells(i, 1).Resize(1, 2).Value
If rng2.Cells(i, 11) Like "*4'dia**Invert*" And _ 'THIS PART IS NOT ADDING A ROW
rng2.Cells(i, 14) Like "*Toho*" Then
rng2.Cells(i, 11).Offset(1).EntireRow.Insert
rng2.Cells(i, 3).Offset(1).Resize(1, 9).Value = _
Array("1", "F14050XJ", "Yes", "", "", "185", "Production", "500", "FLOWLINE,4' Diameter")
rng2.Cells(i, 1).Offset(1).Resize(1, 2).Value = rng2.Cells(i, 1).Resize(1, 2).Value
ElseIf rng2.Cells(i, 11) Like "*5'dia**Invert*" And _ 'THIS PART IS NOT ADDING A ROW
Not rng2.Cells(i, 14) Like "*Toho*" Then
rng2.Cells(i, 11).Offset(1).EntireRow.Insert
rng2.Cells(i, 3).Offset(1).Resize(1, 9).Value = _
Array("1", "F15050J", "Yes", "", "", "150", "Production", "500", "FLOWLINE,5' Diameter")
rng2.Cells(i, 1).Offset(1).Resize(1, 2).Value = rng2.Cells(i, 1).Resize(1, 2).Value
End If
End If
Next i
End Sub