Maximum

B

Bobby

How can I find in VBA the maximum value in a string. I.E:

Sub test()
Dim x As Variant
Dim y As String

Set x = "100 200 300 400"
y = WorksheetFunction.Max(x)

End Sub

This will not work!

Thank's for the help!
 
D

Dave Peterson

Maybe you could use something like:

Option Explicit
Sub test2()
Dim x As Variant
Dim y As Double

x = Array(100, 200, 300, 400)
y = WorksheetFunction.Max(x)

End Sub

ps. You use the Set keyword with objects--not simple variables.
 
D

Dana DeLouis

Bobby said:
How can I find in VBA the maximum value in a string. I.E:

Sub test()
Dim x As Variant
Dim y As String

Set x = "100 200 300 400"
y = WorksheetFunction.Max(x)

End Sub

This will not work!

Thank's for the help!

the maximum value in a string.

One idea...

Sub Demo()
Dim s
s = "100 200 300 400"
s = Replace(s, Space(1), ",")
s = Replace("Max(#)", "#", s)

Debug.Print Evaluate(s)
End Sub

= = =
HTH
Dana DeLouis
 
B

Bobby

 > the maximum value in a string.

One idea...

Sub Demo()
    Dim s
    s = "100 200 300 400"
    s = Replace(s, Space(1), ",")
    s = Replace("Max(#)", "#", s)

    Debug.Print Evaluate(s)
End Sub

= = =
HTH
Dana DeLouis

Thank's Dana
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top