Error #VALUE! when calculate with result of hlookup - excel-formula

This first formula, i used HLOOKUP to fill data for column J OK
=HLOOKUP(LEFT(C6,1),$E$18:$H$19,2,0)
A second formula, i would like to fill data for column K but error #VALUE!
=((G6/26)*H6*J6)+((G6/26)*I6)
Description image
What am I doing wrong?
Thanks in advance!

Excel's overhead can take care of text-that-look-like-a-number to true number conversion 'on the fly'. All you have to do is stick the text in a maths operation and the conversion is automatic.
="1"+1 'result is 2
=1+1 'result is 2
However, if there are extra characters attached to the text-that-look-like-a-number, Excel cannot perform the conversion and throws a #VALUE! error.
="1"&char(10)+1 'result is #VALUE!
The easiest way to check for non-printing¹ (invisible) characters like line feeds or CHAR(0) atoms is to check the length with the LEN(...) function. If the length is greater than what we can see there is likely non-printing characters attached.
For your data,
Not only is the 17 left-aligned (the default for Text), the LEN function shows that it is 3 characters wide, not the 2 characters wide that we can see.
Go back to the original value where HLOOKUP retrieved its lookup and select the cell and tap F2. Using the arraow keys will show where the rogue character is.
Delete the rogue character and your formula should resolve properly.
¹ Typical non-printing characters are line feeds (Chr(10)) and carriage returns (Chr(13), non-breaking spaces (Chr(160), atom delimiters like Chr(0) or zero-width spaces (Crw(8203). Text-that-look-like-a-number that has rogue characters attached is very common from data imported of copied from web sources.

Related

Create Data Validation in Excel Sheet

I have a data validation issue.
My cell reference should be 2 letters then 4 digits then 1 letter
As Example - AB1234A, xY0123z
Need to consider Both simple and Capital as well. Other way of input need to reject.
Use custom validation formula for that cell.
Check if first 2 are letters with ISTEXT and LEFT formulas. If 3rd, 4th, 5th and 5th are numbers with ISNUMBER and MID formulas, check if length is 7 symbols with LEN and so on. Wrap everything with AND
And you will get something like this:
=AND(LEN(C4)=7,ISTEXT(LEFT(C4,2)),ISNUMBER(VALUE(MID(C4,3,4))),ISNUMBER(RIGHT(C4,1)+1)=FALSE)
(Note that if you extract 1 symbol with LEFT, RIGHT or MIDand it is a number it will be treated like text. Workaround is to add any number and check if it converts to a number (adding number to actual text would give value error)

Excel Formula separate the left numeric values from the data

I have some data in Col"K" where from i am just trying to get the left characters as i tried in Col"H" using formula.
But what i used is Left function like =Function(cell,10) that is not the correct way characters can be more than 10 or less than 10.
1st formula should be dynamic to get the left numeric values.
2nd Formula should copy and paste the same numeric values until next value comes as available in Col"I"
I tried to make it but what i can do is to create left function and do not know how to develop it dynamic.
Any help will be appreciated.
Sheet Link
https://docs.google.com/spreadsheets/d/1nJZeWDZ0EWgmWB0z17xU93fjIOFsu46EL37IJqJzZ_0/edit?usp=sharing
This formula should do the job.
[J2] =IFERROR(TRIM(LEFT(L2,FIND("-",L2)-1)),J1)
Note that it will fail if placed in row 1 and there is no dash in L1.
Use find function to get numeric characters length.
=iferror(trim(left(L3,FIND("-",L3)-1)),M2)
Here we are finding the separator "-" in your text and it gives us index number of separator.
Then picking text from start to before index number i.e., Numeric value and removing blank spaces, if any, using trim function. If we don't have number/separator in the text then showing previous cell value using iferror function. So, Make sure first row always has numeric value.
Same has implemented in the sheet you have shared
As per the latest data I have updated my answer as below , now it is checking output is numeric or not:
=IF(COUNT(FIND({0,1,2,3,4,5,6,7,8,9},J9))=0,K8,TRIM(LEFT(J9,FIND("-",J9)-1)))

Extract Last 2 line breaks from excel

I'm trying to achieve the below:
I would like cell AD3 to pull in the last 2 lines of text from cell AC3, which will be variable and often changing. The text in cell AC3 is all separated by line breaks.
In case you're wondering, currently I just have the values typed into cell AD3 for demonstration of my goal.
Thank you!
Let's break this down. For ease of writing, I use A1.
You first want to know how many rows are in the cell.
=LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(10),""))
This formula returns a count of the character 10, which is the character used for a line break in a cell. If the cell has 5 rows, there will be 4 line break characters. If you want to return the last 2 rows, you want everything after the one but last line break character. To identify the one but last line break, subtract 1.
=LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(10),""))-1
Replace the one but last line break character with a character that you know will otherwise not be in your cell, for example the character with code 160, which is a non-printable blank.
=SUBSTITUTE(A1,CHAR(10),CHAR(160),LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(10),""))-1)
Next, you want to find the position of the character 160
=FIND(CHAR(160),SUBSTITUTE(A1,CHAR(10),CHAR(160),LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(10),""))-1))
Now that you know the position of that character, you can use MID() to return the text after that character (add 1 to the position of that character). Assume that the last two rows of text in A1 are never more than 99 characters, use that for how many characters you want to return. Or use your favourite big number that will do that.
=MID(A1,FIND(CHAR(160),SUBSTITUTE(A1,CHAR(10),CHAR(160),LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(10),""))-1))+1,99)
Remember to format the cell with the formula to wrap!
Many ways to do this. Here's one that is easily adaptable to returning other lines.
If you have the functions available in your version of Excel, you can use FILTERXML and TEXTJOIN
=TEXTJOIN(CHAR(10),,FILTERXML("<t><s>"&SUBSTITUTE(A1,CHAR(10),"</s><s>")&"</s></t>","//s[position()>last()-2]"))
"<t><s>"&SUBSTITUTE(A1,CHAR(10),"</s><s>")&"</s></t>" creates an XML where the line breaks divide the nodes
the xpath argument "//s[position()>last()-2]") returns the last two nodes. Obviously this can be modified an many ways to return other nodes
TEXTJOIN then joins those nodes with a linebreak.
Return the last 2 lines
In B1, enter formula :
=TRIM(RIGHT(SUBSTITUTE(A1,CHAR(10),REPT(" ",399)),799))

Excel: How to add leading zero to string of numbers separated by comma, if the number is less than 8 digits?

I used =IF(A2=A1,C1&","&B2,B2) to concatenate a string of associated SKUs across multiple rows into one cell. The problem is some of the SKUs start with 0, and this got removed with the formula. (Also, some of the rows are showing up as error cells with the red text and fill. The error message says they are a number being stored as text. But it's not like that with every one, and I don't know why.)
All the SKUs have 8 digits, so the incorrect ones will have 7 digits. For example:
Looks like: 4286000,4286800,4310001,4310801,14872001,14872801,14877001,14877801
Should be: 04286000,04286800,04310001,04310801,14872001,14872801,14877001,14877801
I tried the =TEXT function, and got a funny (wrong) result. For example, in a string where all six SKUs need a leading zero, I added 48 zeros in the format_text section of the function, with commas after every 8 zeros. It put the commas in every three digits, basically outputting as a large single number.
Is this something that can be solved with formulas, or does it require VBA?
Similar to tigeravatar's comment which will return a string instead of a number but will have the lead zero:
=RIGHT("00000000"&B2,8)
or
=RIGHT("00000000"&MAX(len(B2),8))
Basically it adds 8 zeros to the front then takes the last 8 characters. Or in the case of the second formula it will take a minimum of 8 characters and a maximum of the length of what is already in the cell. If you know you only have a minimum of 7 characters, then you could just add 1 zero.
Alternatively you could add the zeros using a REPT function:
=REPT("0",MAX(8-LEN(B2),0))&B2
The max is in there in case you have a number longer which would wind up with a negative value for REPT. In that case, MAX would return 0 instead avoiding the error with REPT. The result of this formula is also a string.
If you want to see a leading zero, but keep the cell value as a number, then you would need to apply custom formatting to the cell. Just remember though the zero is not really there if you go that route, the cell is just displaying things as 8 digits long.
You could just change the cell formatting to a custom 00000000 if it's a visual thing.

How to remove a single Leading space in the numeric column in Excel 2013

I really tried a LOT with in-built functions and also with google search but none of the ways doesn't worked out for expected result.
My exact problem is:
I've few numeric columns which i got from a website and copied directly into excel.
In those columns there is a SINGLE Leading space at the beginning of each number in the cell of the entire column. Example 523946.00. In this number there is a single space before the digit 5.
I tried a lot with TRIM and SUBSTITUTE in-built functions but nothing able to resolve my problem of removing spaces.
And also my expectation is when i select two or multiple cells in the same column(spaces removed) then automatically Excel should show or display the AVERAGE: <Average value> SUM: <total Sum> COUNT: <count value> at the below status bar or bottom ribbon.
Say, AVERAGE: 175.49 COUNT: 2 SUM: 350.98
This type of information is not showing at the bottom. Only i'm able to see COUNT: 2 alone....why?
I want in General Format only. No any special formats.
I'm using MS Excel 2013
Edit:
You can actually just use find and replace.
Copy one of the trouble cells.
Select all the cells containing non break space, and select find and replace.
Paste the copied cell into the find bar, delete everything but the last character (asuming that is the non breaking space).
Leave the replace bar empty and press replace all.
This removes all non breaking spaces. :)
**Old Solution:**You can add nothing with paste special to the whole column where the spaces occur.
First copy an completely empty cell. (! remember this step)
Then select all cells in the column and right click and select paste special.
Then select "add" almost at the bottom (see picture) and press ok.
This will make excel reevaluate the values as if you had modified in and entered the value manually. Excel then correctly converts them to numbers. :)
First make sure you have the column Formatted as you would like. Make sure it is a number with 2 decimal places (or how ever many you need), then also make sure that there is no Indents (Maybe you think the Indent is a space?) And that you have it Aligned to the Left, Or where you want the Data To be. This alone should take care of your issue.
If that doesn't work here a list of possible solutions.
=Value(Trim(A1)) ' Removes all white space before and after the text in A1
=Value(Clean(A1)) 'Removes all non printable Charactersin A1
=Value(SUBSTITUTE(I3," ","")) 'Substitutes(Replaces) all instances of " "(Space) with ""(nothing)
'****Note: With Substitute you can also specify how many
' Substitutes(Replaces) to make of the value
=Value(SUBSTITUTE(I3," ","",1)) ' Same as above but with only remove the FIRST space
=Value(Trim(Clean(A1))) ' Removes all white space before and after the text
' after removing all Non-Printable Characters
=Value(Trim(Clean(Substitute(A1," ","")))) ' Removes all white space before and after the
'after removing all Non-Printable Characters
' And after replaceing all spaces with nothing
=Value(Right(A1, Len(A1)-1)) ' This takes the End of your text by the number of characters
' in the value Except the First (In your case should be the Space)
=Value(SUBSTITUTE(I6,CHAR(160),"")) 'To help with the non breaking spaces also.
If nothing works could you please share Why you would like to remove the space? As in what you are trying to do with the data? As maybe that will open more solutions
With Ole Henrik Skogstrøm's Suggestion added Value around the functions to get the result as a value.
It may be Excel is treating your cells as text data. Is the fun Green Triangle present?
This is a common problem in excel. Forcing numeric is easier than text. Just format a column as number or General and then put in the function value() into the cells.
Things can be cleaned up from there with Copy/Paste Special values and then remove the original column.
Using Excel 2007
brettdj answered this for me. This is what worked for me and it was SIMPLE!!
To remove the CHAR(160) directly without a workaround formula go to
Find & Replace
in the Find What hold ALT and type 0160 using the numeric keypad
then Leave Replace With as blank and select Replace All
In your case, since you always have a string of numbers, where you want to remove just the first character (a space), this formula should work:
=RIGHT(A1,LEN(A1)-1)
The numbers can vary in length, important is only, that you want to remove just 1, (or 2, or 3 etc) characters. It will still work. {If you had 2 empty spaces in front, then you would use in the formula -2, if three -3, etc)
However, if you had always a different amount of blanks in your string of numbers, like I had, you could use this formula, which worked for me:
=VALUE(SUBSTITUTE(TRIM(A1),CHAR(160),""))
,assuming that the issue you are facing is code "160".
That you can find by typing: =code(A1), which in my case gave me the result "160". Therefore char(160) in the formula above.

Resources