willyboy58
Technical User
Looping problem
I have some rows of data that I need to delete. If there IS NOT a customer number in column A AND column C (called StepCell) = 80, 81, or 82, that is OK.
But if there IS NOT a customer number in column A and column C is NOT equal to 80, 81, 82 then I want to delete all information in that row.
Have to open task manager to stop procedure. My procedure with REM’d notes is below.
-----------------
Sub DeleteRowWithNoCustNumber()
Dim StepCell As String
Range("A1"
.Select
StepCell = ActiveCell.Offset(0, 2)
'start of loop
Do
With ActiveCell
If .Offset(0, 0).Formula = "" And StepCell <> 80 Or 81 Or 82 Then
ActiveCell.Offset(0, 0).EntireRow.Select
Selection.Delete
Else
End If
'the following line is needed for the loop. step down one row to the next cell
ActiveCell.Offset(1, 0).Select
End With
'i believe that it is working to this point but cannot 'verify because procedure will not stop running. There is only about 3600 rows of data to work with at this point. The loop does not stop running even when ActiveCell And StepCell = "" (next line)
Loop Until ActiveCell And StepCell = ""
'when finished should go back to "A1"
Range("A1"
.Select
End Sub
---------------------------
What am I doing wrong? TIA. Bill
I have some rows of data that I need to delete. If there IS NOT a customer number in column A AND column C (called StepCell) = 80, 81, or 82, that is OK.
But if there IS NOT a customer number in column A and column C is NOT equal to 80, 81, 82 then I want to delete all information in that row.
Have to open task manager to stop procedure. My procedure with REM’d notes is below.
-----------------
Sub DeleteRowWithNoCustNumber()
Dim StepCell As String
Range("A1"
StepCell = ActiveCell.Offset(0, 2)
'start of loop
Do
With ActiveCell
If .Offset(0, 0).Formula = "" And StepCell <> 80 Or 81 Or 82 Then
ActiveCell.Offset(0, 0).EntireRow.Select
Selection.Delete
Else
End If
'the following line is needed for the loop. step down one row to the next cell
ActiveCell.Offset(1, 0).Select
End With
'i believe that it is working to this point but cannot 'verify because procedure will not stop running. There is only about 3600 rows of data to work with at this point. The loop does not stop running even when ActiveCell And StepCell = "" (next line)
Loop Until ActiveCell And StepCell = ""
'when finished should go back to "A1"
Range("A1"
End Sub
---------------------------
What am I doing wrong? TIA. Bill