Maximum

  • Thread starter Thread starter Bobby
  • Start date Start date
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!
 
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.
 
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
 
 > 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
 
Back
Top