Combine UCase and IsNumeric

nniedzielski

Well-known Member
Joined
Jan 8, 2016
Messages
598
Office Version
  1. 2019
Platform
  1. Windows
I am running this code to delete any row that shows Yes in column C, False in column M, Or the number 1 in column AH, when i run this, only the Yes and False are being found and deleted. The 1's remain. I am however, not getting any errors, it just doesnt seem to be finding them.

VBA Code:
Dim nc As Long, i As Long, k As Long, lr As Long
    
    Set ws = Sheets("Data")
    With ws
      nc = .Cells.Find(What:="*", LookIn:=xlFormulas, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column + 1
      lr = .Columns("C:AH").Find(What:="*", LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
      a = Application.Index(.Cells, Evaluate("row(2:" & lr & ")"), Array(3, 14, 34))
      ReDim b(1 To UBound(a), 1 To 1)
      For i = 1 To UBound(a)
        If UCase(a(i, 1)) = "YES" Or UCase(a(i, 2)) = "FALSE" Or IsNumeric(a(i, 3)) And a(i, 3) = 1 Then
          b(i, 1) = 1
          k = k + 1
        End If
      Next i
      If k > 0 Then
        Application.ScreenUpdating = False
        Application.Calculation = xlCalculationManual
        With .Range("A2").Resize(UBound(a), nc)
          .Columns(nc).Value = b
          .Sort Key1:=.Columns(nc), Order1:=xlAscending, Header:=xlNo
          .Resize(k).EntireRow.Delete
        End With
        Application.Calculation = xlCalculationAutomatic
        Application.ScreenUpdating = True
      End If
    End With
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
here is an option: try this on a COPY of your file.

VBA Code:
Sub DeleteRows() 'This macro will delete the entire row if there is a data match anywhere in the range.

On Error Resume Next
Dim lr as integer
lr = Columns("C:AH").Find(What:="*", LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

    With Range("C2:C"&lr)
        .Replace "Yes", False, xlWhole
        .SpecialCells(xlCellTypeConstants, 4).EntireRow.Delete
    End With

    With Range("M2:M"&lr)
        .Replace "False", False, xlWhole
        .SpecialCells(xlCellTypeConstants, 4).EntireRow.Delete
    End With

    With Range("AH2:AH"&lr)
        .Replace 1, False, xlWhole
        .SpecialCells(xlCellTypeConstants, 4).EntireRow.Delete
    End With

On Error GoTo 0
End Sub
 
Upvote 0
Your code works fine for me, is col AH a formula? If so what is the formula?
 
Upvote 0
Ok (y) let us know it it goes.
 
Upvote 0
Glad you sorted it & thanks for letting us know.
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,543
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top