View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Mitchell_Collen via OfficeKB.com Mitchell_Collen via OfficeKB.com is offline
external usenet poster
 
Posts: 27
Default VBA code deleting everything not just rows with specified values. Please help.

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

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200710/1