M
Mitchell_Collen via OfficeKB.com
Hi VBA Professionals.
Please see my code. I am trying to only delete rows in an excel sheet where
the value is equal to each string value provided below. However when I run
this macro it deletes everything. I don't know what I am doing wrong. I won't
lie. I am no programmer. Will you please help me with this?
Thanks, Misty
Sub Macro1()
' Keyboard Shortcut: Ctrl+d
'Sub DelEmptyRow()
Rng = Selection.Rows.Count
ActiveCell.Offset(0, 0).Select
Application.ScreenUpdating = False
For i = 1 To Rng
If ActiveCell.Value = "Outpatient Chronic" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
If ActiveCell.Value = "Dialysis Treatments" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
If ActiveCell.Value = "Medications" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
If ActiveCell.Value = "Ferrlecit*" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
If ActiveCell.Value = "Zemplar*" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
If ActiveCell.Value = "Cathflo*" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
If ActiveCell.Value = "Clarity" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
Next i
Application.ScreenUpdating = True
End Sub
Please see my code. I am trying to only delete rows in an excel sheet where
the value is equal to each string value provided below. However when I run
this macro it deletes everything. I don't know what I am doing wrong. I won't
lie. I am no programmer. Will you please help me with this?
Thanks, Misty
Sub Macro1()
' Keyboard Shortcut: Ctrl+d
'Sub DelEmptyRow()
Rng = Selection.Rows.Count
ActiveCell.Offset(0, 0).Select
Application.ScreenUpdating = False
For i = 1 To Rng
If ActiveCell.Value = "Outpatient Chronic" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
If ActiveCell.Value = "Dialysis Treatments" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
If ActiveCell.Value = "Medications" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
If ActiveCell.Value = "Ferrlecit*" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
If ActiveCell.Value = "Zemplar*" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
If ActiveCell.Value = "Cathflo*" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
If ActiveCell.Value = "Clarity" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
Next i
Application.ScreenUpdating = True
End Sub