Is there a VBA Function to convert the string "(1000)" to the number -1000

Mackeral

Board Regular
Joined
Mar 7, 2015
Messages
232
Office Version
  1. 365
Platform
  1. Windows
My old memory remembers one, but I don't remember it's name.

Here is the one I wrote but it's not nearly as concise as a function call:
VBA Code:
Function Value_(Arg)
    ' Returns the Value of the string "Arg"
     
    Prog = "Value_"
    
    If Left(Arg, 1) <> "(" Then
        TEMP = Arg
        GoSub Error_Check
        Value_x = Val(Arg)
        
    ElseIf Right(Arg, 1) = ")" Then
        TEMP = Mid(Left(Arg, Len(Arg)), 2)
        GoSub Error_Check
        Value_ = -Val(TEMP)
        
    Else
        Msg1 = "Unmatched Parenthesis in"
        Call Msg_Err(Prog, Msg1, Quote(Arg))
        Stop
        
    End If
    
    Exit Function
    
'   = = = = = = = = = = = = =  = = = = = =
Error_Check:
    If Not IsNumeric(Arg) Then
        Msg1 = """Arg"" is not a valid number:"
        Call Msg_Err(Prog, Msg1, Quote(Arg))
        Exit Function
    End If
    Return
    
End Function ' Value_x
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
You can just add 0 to the string
VBA Code:
   MsgBox "(1000)" + 0
 
Upvote 0
Or use CDbl or CLng depending on the desired result type
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,286
Members
449,076
Latest member
kenyanscott

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