ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Adding a row immediately following a "true" statement (https://www.excelbanter.com/excel-discussion-misc-queries/252869-adding-row-immediately-following-true-statement.html)

Robb

Adding a row immediately following a "true" statement
 
I need to add a row (keeping the format above) immediately following a 'true'
statement. I.e. if column k="C","R","RB" or "P", add row replacing
"C","R","RB" or "P" with "S".

I am trying to develop a spreadsheet to handling our invoicing for a
specific customer. Each of the above product codes needs an "S" line (for
shipping cost)




Bob Phillips[_4_]

Adding a row immediately following a "true" statement
 
Here's some code

Public Sub ProcessData()
Dim i As Long
Dim LastRow As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "K").End(xlUp).Row
For i = LastRow To 1 Step -1

If .Cells(i, "K").Value2 = "C" Or .Cells(i, "K").Value2 = "R" Or
_
.Cells(i, "K").Value2 = "RB" Or .Cells(i, "K").Value2 = "P"
Then

.Rows(i + 1).Insert
.Cells(i + 1, "K").Value = "S"
End If
Next i
End With

End Sub

HTH

Bob

"Robb" wrote in message
...
I need to add a row (keeping the format above) immediately following a
'true'
statement. I.e. if column k="C","R","RB" or "P", add row replacing
"C","R","RB" or "P" with "S".

I am trying to develop a spreadsheet to handling our invoicing for a
specific customer. Each of the above product codes needs an "S" line (for
shipping cost)







All times are GMT +1. The time now is 01:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com