Adding a row immediately following a "true" statement

R

Robb

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)
 
B

Bob Phillips

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top