Convert String array to Long array

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,815
Office Version
  1. 2016
Platform
  1. Windows
Code:
Sub test()

    Dim s As String
    Dim Ar() As String
    
    s = "1,2,3,4,5"
    ar = Split(s, ",")
    MsgBox WorksheetFunction.Max(ar)

End Sub
The above Split Function returns a String array - Is there a way to convert this String array to a Long array so that we can obtain the Max element (ie: 5) but w/o looping though the array and converting each element one by one ?
 
This board never ceases to amaze me with its knowledgeable and helpful members.

PGC's solution does not only work directly on the string array (as opposed to the Evaluate Function which works on the 's' String variable) it also works on large String arrays. Beautiful !

Just how did using the Power function to solve this occur to you ? :) - I had tried using the Product function (Multiplying the array by 1) to force a data conversion in a similar way before posting the question on the board but obviously didn't work.

Again, Thanks to everybody who answered.
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi Jaafar

Nice problem, as usual. I'm glad this time I was able to contribute.

I knew that Sum or Product or SumProduct would'n work with the text parameter. Power seemed a good option and that's why I tested it.

Cheers!
 
Upvote 0

Forum statistics

Threads
1,225,156
Messages
6,183,223
Members
453,152
Latest member
ChrisMd

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