Excel vba - convert string to number
Asked Answered
U

2

15

So, I used the left function to take the first 4 characters of a string and I need to run a vlookup with it, but it won't find the match because it's looking through numbers.

I want to do this in a macro, so I'm not sure about the syntax. Can someone help?

Unwisdom answered 30/9, 2011 at 20:16 Comment(0)
C
38

use the val() function

Connote answered 30/9, 2011 at 20:22 Comment(0)
O
5

If, for example, x = 5 and is stored as string, you can also just:

x = x + 0

and the new x would be stored as a numeric value.

Oaks answered 22/5, 2016 at 10:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.