How can I get excel to calculate with a cell if its contents is a number and letters?
Eg.
A1= 2
A2= 230gr
I want to calculate cell A2 multiplied by A1 (A1*A2) the answer is supposed to be "460"
* * * * * * *
How beautiful it is to excel, and the goodness of giving from your heart. || Always strive to excel, but only on weekends. - Richard Rorty & Robert Mondavi
If we assume the right two characters of A2 are always text then:
=A1*LEFT(A2,LEN(A2)-2)
Will the string always be NNNxx, where N= numeric and x = alpha?
Palmetto
Do you know . . . ?
You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.
depends what's actually in a2 but
=A1*LOOKUP(9.99E+307,--MID(A2,MIN(FIND({1,2,3,4,5,6,7,8,9,0},A2&1234567890)),ROW(INDIRECT("1:"&LEN(A2)))))
is one way
"Unless otherwise stated all my comments are directed at OP"
Mojito connoisseur and a dabbler in Cisco
where does code go ?
look here
how to insert code
how to enter array formula
why use -- in sumproduct
recommended reading
wiki Mojito
how to say no convincingly
most important thing you need
Martin Wilson: SPV
and RSMBC
Well my strings might all be different.
I might have string vary from 2-to-4 Numeric values and 1-to-2 alpha
* * * * * * *
How beautiful it is to excel, and the goodness of giving from your heart. || Always strive to excel, but only on weekends. - Richard Rorty & Robert Mondavi
It would be best to get rid of the text, and put the units, if necessary, in another column.
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
You could use a User Defined Function to remove the text characters...
Public Function RmvText(inString As String) Dim x As Integer 'LOOPING COUNTER Dim vText As Variant 'CHARACTER HOLDER For x = 1 To Len(inString) vText = Mid(inString, x, 1) If IsNumeric(vText) Or vText = "." Then RmvText = RmvText & vText Next x End Function
Last edited by dangelor; 12-25-2011 at 09:21 PM. Reason: Added test for decimal
Last edited by anonymust; 12-25-2011 at 06:21 PM. Reason: Two answers in one.
* * * * * * *
How beautiful it is to excel, and the goodness of giving from your heart. || Always strive to excel, but only on weekends. - Richard Rorty & Robert Mondavi
@martindwilson, your formula is returning "TRUE" instead of a number. I am trying to understand the concept but I can't fully understand the principles used here.
abousetta
Please consider:
Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.
Martin's formula returns a valid number (460, using your examples in post #1) for me.
Perhaps you should upload a sample workbook.
Palmetto
Do you know . . . ?
You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.
Palmetto, you are right. I opened a new workbook and tested it again and it worked this time.
abousetta
Please consider:
Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.
If your numbers are always on starting,
=A1*LOOKUP(9.9999E+307,--LEFT(0&A2,ROW($A$1:$A$20)))
See attached file.I will never figure out how and where to use this, but thanks
Last edited by dangelor; 12-25-2011 at 09:50 PM. Reason: Edited UDF to check for decimal
Would it not be easier to format A2 & A3
Format Cells > Number > Custom
Type:=
Then in A3#,##0"gr"
Just a thought.=A1*A2
If you need any more information, please feel free to ask.
However, if this takes care of your needs, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED. It helps everybody! ....
Also
If you are satisfied by any members response to your problem please consider using the small Star icon botom left of thier post to show your appreciation.
What I am basically trying to do it calculate the cost of food items per gram or per milliliter and then see which on is the cheapest by the Kilo/Kilogram or Liter
I've altered a function to something like this:
=(-A1/LOOKUP(0,-LEFT(A2,{1,2,3,4})))*1000
Where A1 is the cost of the item and A2 is the quantity of the item (in grams, milliliters, liters and kilo/kilogram,)
Which is in layman's =(cost of food divided by how much ml/g received) * 1000
Spaces
If I have "121gr" in a cell it works perfectly.. but when I have "121 gr" in a cell it doesnt *notice the spacing between the alpha and numeric value*
Different unit conversion? (convert KG and L into milliliters and grams)
Sometimes I enter my data with: "kg" "L" and "K", examples:
- 1kg
- 1.2 L
- 2.5k
- 2.5 KG
- 1.4L
*notice the spacing between the alpha and numeric value*
* * * * * * *
How beautiful it is to excel, and the goodness of giving from your heart. || Always strive to excel, but only on weekends. - Richard Rorty & Robert Mondavi
You would be much better doing as shg suggested, put the units in a seperate cell.
If you need any more information, please feel free to ask.
However, if this takes care of your needs, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED. It helps everybody! ....
Also
If you are satisfied by any members response to your problem please consider using the small Star icon botom left of thier post to show your appreciation.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks