I am modifying a borrowed snippet that has worked for me before. But since my understanding is limited, I am stepping through as I add 'variables' I am getting stuck on one and I cannot see why.
I have a sheet with about 16k rows. for some rows the person named has filed bankruptcy so I want to remove them. The cells denoting bankruptcy are in the Street address column "I" although I will be expanding this to J, and K as well
The problem is various users adding to the sheet have denoted bankruptcy differently. They may have entered CH 7, or CH7, or ch7, or Chap7, and so on, and the same for chapter 13 as well.
So I have the ch 7's working fine but seemingly randomly, because I can't find the reason and it does not seem specific to the line or the line content, it stops with Runtime error 424 Object Required
In the code below it is stopping on the line reading:
If .Value = "chap 13" Then
Maybe there is a more efficient way to enter the "ch7" versions?
Your help is appreciated
I have a sheet with about 16k rows. for some rows the person named has filed bankruptcy so I want to remove them. The cells denoting bankruptcy are in the Street address column "I" although I will be expanding this to J, and K as well
The problem is various users adding to the sheet have denoted bankruptcy differently. They may have entered CH 7, or CH7, or ch7, or Chap7, and so on, and the same for chapter 13 as well.
So I have the ch 7's working fine but seemingly randomly, because I can't find the reason and it does not seem specific to the line or the line content, it stops with Runtime error 424 Object Required
In the code below it is stopping on the line reading:
If .Value = "chap 13" Then
Code:
Sub DeleteCH7()
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
'We use the ActiveSheet but you can replace this with
'Sheets("MySheet")if you want
With ActiveSheet
'We select the sheet so we can change the window view
.Select
'If you are in Page Break Preview Or Page Layout view go
'back to normal view, we do this for speed
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
'Turn off Page Breaks, we do this for speed
.DisplayPageBreaks = False
'Set the first and last row to loop through
Firstrow = .UsedRange.Cells(1).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'We loop from Lastrow to Firstrow (bottom to top)
For Lrow = Lastrow To Firstrow Step -1
'We check the values in the I column in this example also J, K
With .Cells(Lrow, "I")
If Not IsError(.Value) Then
If .Value = "ch7" Then .EntireRow.Delete
If .Value = "ch 7" Then .EntireRow.Delete
If .Value = "CH7" Then .EntireRow.Delete
If .Value = "CH 7" Then .EntireRow.Delete
If .Value = "CHAP 7" Then .EntireRow.Delete
If .Value = "chap 7" Then .EntireRow.Delete
If .Value = "CHAP7" Then .EntireRow.Delete
If .Value = "chap 7" Then .EntireRow.Delete
If .Value = "CH13" Then .EntireRow.Delete
If .Value = "CH 13" Then .EntireRow.Delete
If .Value = "CHAP 13" Then .EntireRow.Delete
If .Value = "chap 13" Then .EntireRow.Delete
'This will delete each row with the Value "ch7"
'in Column I, case sensitive.
End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
Your help is appreciated