I'm looking for a simple Excel VBA or formula that can convert an entire row in Excel from 'number stored as Text' to an actual Number for vlookup reasons.
Can anyone point me in the right direction?
I'm looking for a simple Excel VBA or formula that can convert an entire row in Excel from 'number stored as Text' to an actual Number for vlookup reasons.
Can anyone point me in the right direction?
I wrote a custom vlookup function that doesn't care about data formats. Put this into a module in VBA and use = VLOOK instead of = VLOOKUP
The easiest way I can think of is using the built-in function =VALUE(TEXT_TO_CONVERT_TO_STRING).
I did find this, but does anyone have a formula as well?
http://www.ozgrid.com/forum/showthread.php?t=64027
This should work if you add it before your vlookup or index/match lines:
Try this:
To use it, simply select the relevant block of cells with the mouse, and then run the macro (Alt+F8 to bring up the dialogue box). It will go through each cell in the selected range and convert whatever value it holds into a number.
Better Approach
You should use
INDEX(MATCH)
instead ofVLOOKUP
becauseVLOOKUP
behaves in an unpredictable manner which causes errors, such as the one you're presumably experiencing.Using
0
as the last argument toMATCH
means the match must be exactHere is some more in-depth information on
INDEX(MATCH)
-ingFurther
Add zero
+0
to convert a value to a number.This can be (dangerously) extended with
IFERROR()
to turn non-numeric text into a zero:=A2+0
=IFERROR(A2+0,0)
For the inverse, you can catenate an empty string
&""
to force the value to be a string.Notes
If
0
is not used as the last argument toMATCH
, it will find all sorts of unexpected "matches" .. and worse, it may find a different value even when an exact match is present.It often makes sense to do some extra work to determine if there are duplicates in the
MATCH
lookup column, otherwise the first value found will be returned (see example).Help with
MATCH
comes from here, notably the matching logic the 3rd argument controls.