![]() |
Convert a string to number
I am using "Right(Environ("UserName"), 1)" to pull the last character in the
username. This character happens to be a number. Since it is a string, I need to know have to convert to a numeric in order to use in a formula. Thanks |
Convert a string to number
Dim num as Long
num = Right(Environ("UserName"), 1) Or to make it more robust Dim num as Variant num = Right(Environ("UserName"), 1) if isnumeric(num) then num = clng(num) end if -- Regards, Tom Ogilvy "WLMPilot" wrote in message ... I am using "Right(Environ("UserName"), 1)" to pull the last character in the username. This character happens to be a number. Since it is a string, I need to know have to convert to a numeric in order to use in a formula. Thanks |
Convert a string to number
I think it's not a bad idea to check if a string is numeric before
converting, just in case: res = Right(Environ("USERNAME"), 1) If IsNumeric(res) Then res = CInt(res) Else MsgBox "Can't convert" End If -- urkec "Vergel Adriano" wrote: CInt(Right(Environ("UserName"), 1)) -- Hope that helps. Vergel Adriano "WLMPilot" wrote: I am using "Right(Environ("UserName"), 1)" to pull the last character in the username. This character happens to be a number. Since it is a string, I need to know have to convert to a numeric in order to use in a formula. Thanks |
Convert a string to number
CInt(Right(Environ("UserName"), 1))
-- Hope that helps. Vergel Adriano "WLMPilot" wrote: I am using "Right(Environ("UserName"), 1)" to pull the last character in the username. This character happens to be a number. Since it is a string, I need to know have to convert to a numeric in order to use in a formula. Thanks |
All times are GMT +1. The time now is 05:22 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com