This code works perfectly on text, but doesn't work on numbers. Can it be modified to work on both?

VBAProIWish

Well-known Member
Joined
Jul 6, 2009
Messages
1,027
Office Version
  1. 365
Platform
  1. Windows
Here's the code...


Code:
Sub Del_Rows_w_X_inColX_Unless()
Dim cell_to_check As Variant
Dim range_to_check As Range
Dim nCol As Long
Dim nCol2 As Long
Dim rCount As Long
With ActiveSheet
    nCol = Application.Match("Region", .Rows(1), 0)
    nCol2 = Application.Match("Event", .Rows(1), 0)
    For rCount = .UsedRange.Rows.Count To 2 Step -1
        Select Case UCase(.Cells(rCount, nCol2).Value)
            Case "123", "124", 135"
                'Do Nothing
            Case Else
                Select Case UCase(.Cells(rCount, nCol).Value)
                    Case "NORTH"
                        .Rows(rCount).EntireRow.Delete
                End Select
        End Select
    Next
End With

End Sub

It's supposed to delete any rows in the "North" column unless the "Event" column says "123", "124" or "125", but it deletes those rows also.

If I change the numbers to any text, it will keep those rows. Can this be modified to work on numbers and text?

Thanks much
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
try changing this:

Select Case UCase(.Cells(rCount, nCol2).Value)

to

Select Case Val(.Cells(rCount, nCol2).Value)

Also you are missing a quote before 135 in the case statement
 
Last edited:
Upvote 0
Try removing the quotes from around your number, i.e.
Code:
Case 123, 124, 135
You only put quotes around text entries.
 
Upvote 0

Forum statistics

Threads
1,224,882
Messages
6,181,546
Members
453,053
Latest member
ezzat

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