What I am trying to do:
Exporting excel doc from Salesforce. I am trying to delete some rows based on a condition, then add rows based on a different set of conditions. Being new to VBA, I've browsed the forums and googled some sample codes, but cannot get them to work fully.
Adding rows:
Column C = Quantity. Need to add rows below based on the value in column C. If quantity = 3 - I want to add 2 blank rows below. If quantity = 4 - 3 blank rows below...
Tried:
Sub BlankLine()
Dim Col As Variant
Dim BlankRows As Long
Dim LastRow As Long
Dim R As Long
Dim StartRow As Long
Col = "C"
StartRow = 15
BlankRows = 1
LastRow = Cells(Rows.Count, Col).End(xlUp).Row
Application.ScreenUpdating = False
With ActiveSheet
For R = LastRow To StartRow + 1 Step -1
If .Cells(R, Col) > 1 Then
.Cells(R + 1, Col).EntireRow.Insert Shift:=xlDown
End If
Next R
End With
Application.ScreenUpdating = True
End Sub
This works, but only adds a single row below - I need it to add rows based on the value of column C = 'quantity'.
Deleting Rows:
Column A = Product Names. If any product name contains MAINT or APP, I need to delete that row. Tried:
Sub test()
With ActiveSheet
.AutoFilterMode = False
With Range("A1", Range("A" & Rows.Count).End(xlUp))
.AutoFilter 1, "*Maint*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
End Sub
This also works, but deletes the top row once done, so I lose some information.
Any suggestions on how to approach this is greatly appreciated!
add rows based on the value of column Cplease explain.