alphanumeric

Ralter649

New Member
Joined
Oct 20, 2017
Messages
36
I am tring to delete alphanumerics that are < or > a given amount in a columb. An example of the values i am going workingwith are: (1 letter/ 4 numbers/2 letters) s1001pg, s1022pl, s1042hd, ect.

I can not figure out how to delete anything > then ex: s1022pl
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Any time you have anything other than numbers in a cell, that cell becomes text. So you are asking excel to decide if Tuesday is < or > cat. You need to break out the numbers, then you can try what you want to do
 
Upvote 0
Just another thought on how to do it converting individual characters into ascii and comparing that way.

Code:
Sub AlphaCompare()
    Dim strMin As String, strMax As String
    Dim cell As Range, rng As Range
    Dim strLimit As String
    
    Set rng = Range("A1:A50") ' Your range of values you want to parse
    strMin = Range("B1").Value ' Just need to adjust ranges here to suit where your data and constraints are
    strMax = Range("B2").Value
    If strMin = "" And strMax <> "" Then GoTo UpperLimit
    If strMax = "" And strMin <> "" Then GoTo LowerLimit
    If strMin <> "" And strMax <> "" Then strLimit = "Ranged": GoTo UpperLimit
    If strMin = "" And strMax = "" Then End
    
UpperLimit:
    For Each cell In rng
        If Len(strMax) > Len(cell.Value) Or cell.Value = "" Then GoTo nextUpper
        If Len(strMax) < Len(cell.Value) Then cell.Clear: GoTo nextUpper
        For i = 1 To Len(cell.Value)
            If Asc(LCase(Mid(cell.Value, i, 1))) > Asc(LCase(Mid(strMax, i, 1))) Then cell.Clear: GoTo nextUpper
            If Asc(LCase(Mid(cell.Value, i, 1))) < Asc(LCase(Mid(strMax, i, 1))) Then GoTo nextUpper
        Next i
nextUpper:
    Next cell
    If strLimit = "Ranged" Then GoTo LowerLimit
    End
    
LowerLimit:
    For Each cell In rng
        If Len(strMin) < Len(cell.Value) Or cell.Value = "" Then GoTo nextLower
        If Len(strMin) > Len(cell.Value) Then cell.Clear: GoTo nextLower
        For i = 1 To Len(cell.Value)
            If Asc(LCase(Mid(cell.Value, i, 1))) < Asc(LCase(Mid(strMin, i, 1))) Then cell.Clear: GoTo nextLower
            If Asc(LCase(Mid(cell.Value, i, 1))) > Asc(LCase(Mid(strMin, i, 1))) Then GoTo nextLower
        Next i
nextLower:
    Next cell
    End
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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