Finding Highest Value in A Series of Text Values

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Consider this dynamic range of cells:
wloopkdata_13.xlsm
P
144451W001
244451W002
344451W003
444451W004
544451W005
644451W006
744451S001
844451S002
944451S003
1044451S004
1144452W001
1244452W002
1344452W003
1444452W004
1544452W005
1644452W006
Sheet1


I am looking for a VBA solution in which I can find the highest value of a particular seriers in that range.

For instance, if we assume a series being = 44451W, what is "x" - the largest value (determined by the last three numbers of the string) in that series. In this example, "x" = 6.

Thank you for yuour help!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
As the range is somewhat already sorted a VBA demonstration for starters :​
VBA Code:
Sub Demo1()
     Const S = "44451W"
       Dim Rc As Range
       Set Rc = Range([P1], [P1].End(xlDown)).Find(S & "*", , , , , 2)
    If Not Rc Is Nothing Then
       MsgBox "The last is #" & Val(Replace(Rc.Text, S, "")), 64
       Set Rc = Nothing
    End If
End Sub
 
Upvote 0
Range can be in any order.
VBA Code:
Option Explicit
Sub HighestValue()
Dim Lr&, i&, max&, cell As Range, series As String, arr()
Lr = Cells(Rows.Count, "P").End(xlUp).Row
ReDim arr(1 To Lr, 1 To 1)
series = UCase(InputBox("Input series:"))
For Each cell In Range("P1:P" & Lr)
    If cell.Value Like series & "*" Then
        i = i + 1
        If i = 1 Then
            max = Mid(cell, Len(series) + 1, 255) + 0
        End If
        arr(i, 1) = Mid(cell, Len(series) + 1, 255) + 0
        If arr(i, 1) > max Then
           max = arr(i, 1)
        End If
    End If
Next
MsgBox "max value is: " & max
End Sub
 
Upvote 0
Solution
A variation of my demonstration :​
VBA Code:
Sub Demo1v()
  Const S = "44451W"
    Dim V
        V = Filter(Evaluate("TRANSPOSE(P1:P" & Cells(Rows.Count, 16).End(xlUp).Row & ")"), S, True)
        If UBound(V) > -1 Then MsgBox "The last is #" & Val(Replace(V(UBound(V)), S, "")), 64
End Sub
 
Upvote 0
Thank you bebo021999 and Marc L for sharing your insight and skill. I adapted both to my needs to try. Unfortuantely Marc, I wasn't able to get results from your's, but that may be due in part to my adaptation efforts. bebo21999, your's did work wonderfully.

If interested, here are you versions adapted to my needs ..

Code:
Sub det_RID_1_a(ByRef RID As String) 'thank you Marc L
    Stop
    Dim v
    'ser_dt = ws_gui.Range("B4")
    ser_dt = 44588
    w_ctr = Left(wloc, 1)
    S = ser_dt & w_ctr
    
    With ws_ops
        v = Filter(Evaluate("TRANSPOSE(A2:A" & .Cells(.Rows.Count, 16).End(xlUp).Row & ")"), S, True)
        If UBound(v) > -1 Then MsgBox "The last is #" & Val(Replace(v(UBound(v)), S, "")), 64
    End With

'RID = Range("B4").Value & Left(wloc, 1) & Format(cnt_rid, "000")
End Sub

Code:
Sub det_RID(ByRef RID As String) 'thank you bebo21999
    Dim Lr&, i&, max&, cell As Range, series As String, arr()
    Stop
    With ws_ops
        Lr = .Cells(.Rows.Count, "A").End(xlUp).Row
        ReDim arr(1 To Lr, 1 To 1)
        series = UCase(InputBox("Input series:"))
        For Each cell In .Range("A2:A" & Lr)
            If cell.Value Like series & "*" Then
                i = i + 1
                If i = 1 Then
                    max = Mid(cell, Len(series) + 1, 255) + 0
                End If
                arr(i, 1) = Mid(cell, Len(series) + 1, 255) + 0
                If arr(i, 1) > max Then
                   max = arr(i, 1)
                End If
            End If
        Next
    End With
    RID = series & Format(max + 1, "000")
    MsgBox "Next RID: " & RID
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,882
Members
449,097
Latest member
dbomb1414

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