2

The online broker I use must have the most dysfunctional website worldwide! They provide no "export" function, instead telling their users they can just copy data from tables rendered in their browser, and paste them into Excel. (Really!)

Surprisingly, Excel (2016, for Mac) can be goaded into converting the "positive text numbers" to actual numbers that can be operated on by the numerical functions (SUM typically). However, the "negative text numbers" have defied all efforts I've found to be converted to a negative number.

A "positive text number" is: $123.45
A "negative text number" is: -$543.21 (note the leading text char hyphen)

EDIT:
A "negative text number" is: – $299.55 (Discovered that leading character is NOT a hyphen; it may be an em dash
My apologies for the confusion... I'm now wondering what sort of programmers might use an em dash instead of a minus sign/hyphen in a web page full of numbers, but that's a question for my online broker.

I'm able to convert a "positive text number" in cell A1 as follows: =VALUE(RIGHT(A1,6))

But this does not work on a "negative text number". It gets the number right, but loses the negative sign. I've tried changing the chars value, but that doesn't help.

I've also tried the following without success:
1. multiplying by 1
2. text-to-columns
3. format cells...

Is there a way to do this - other than manually re-entering?

1
  • I'm able to convert a "positive text number" in cell A1 as follows: =VALUE(RIGHT(A1,6)) You extract a part from the middle of cell's value. The text is left-padded with spaces? If so is a text value with negative number value shifted right by a hyphen? Or a hyphen in it replaces a space on 4th position?
    – Akina
    Aug 22, 2018 at 5:04

3 Answers 3

3

I think I've found a simple solution. In one of the cells with the leading em-dash, highlight and copy just the em-dash. Using Excel's "Find and Replace" function, paste the em-dash in the "Find what" block, then type the minus sign into the "Replace with" block. Apply the Replace to all cells you wish to convert.

2
  • P.S. You would still have to reformat to numbers using one of the 3 methods you list in your question.
    – Geoff
    Oct 22, 2019 at 15:48
  • Thanks, that's potentially useful.
    – Seamus
    Oct 22, 2019 at 15:56
2

If cell A1 contains text that is in the format "$123.45" or "-$543.21", you can use the following formula to get the numerical value.

=IF(LEFT(A1,1)="-",0-VALUE(RIGHT(A1,LEN(A1)-1)),VALUE(A1))

If the text starts with a "-", this will get the value of everything after the "-" and make it negative.

1
  • This didn't work initially due perhaps to my ignorance: I had to make one small change as I wasn't getting a TRUE to the symbol you quoted in your macro. I copied and pasted whatever the character is in my "negative text number" cell over the one that you suggested; i.e. =IF(LEFT(I8,1)="–",0-VALUE(RIGHT(I8,LEN(I8)-1)),VALUE(I8)) (Note I8 rather than A1 is immaterial)
    – Seamus
    Aug 22, 2018 at 18:44
0

I'd recommend:

  1. Extract value after $ sign, do not use fixed position
  2. Check the value sign by checking a symbol immediately before $ sign.

So the formula may be

=IF(IF(ISERROR(FIND(MID(A1,FIND("$",A1)-1,1),"<dash><hyphen>")),3,FIND(MID(A1,FIND("$",A1)-1,1),"<dash><hyphen>"))<3,-MID(A1,FIND("$",A1)+1,LEN(A1)),0+MID(A1,FIND("$",A1)+1,LEN(A1)))

where

"<dash><hyphen>" - a literal with possible negative signs (replace placeholders with proper chars in any order, so you obtain 2-symbol literal in shown case)

3 - the number which is greater than the number of chars in previous literal

Those values may be replaced with a reference to a cell which contains all possible "minus" signs (like Z1 and 1+LENGTH(Z1) respectively).


Update. Debugginig the formula.

Create a table on an empty worksheet.

Insert 4 different values to A column (without/with leading spaces, positive/negative).

Insert the below formulas:

Cell          Formula                      Meaning
-------------------------------------------------------------
$B$1          =IF(I1,-G1,0+G1)             Result
$C$1          =LEN(A1)                     Data length in source
$D$1          =FIND("$",A1)                $ position in source
$E$1          =MID(A1,D1-1,1)              symbol before $
$F$1          =FIND(E1,"<dash><hyphen>")   symbol before $ position in hyphens list
$G$1          =MID(A1,D1+1,C1)             number from source
$H$1          =ISERROR(F1)                 correction when no symbol before $ in list
$I$1          =IF(H1,3,F1)<3               define is a source positive or negative

Copy this formula pack to rows 2-4. Check you obtain output like this:

     A        B      C   D   E      F       G    H       I
1    $123     123    4   1   #VAL!  #VAL!   123  TRUE    FALSE   
2    -$234    -234   5   2   -      1       234  FALSE   TRUE    
3      $345   345    6   3          #VAL!   345  TRUE    FALSE   
4      -$456  -456   7   4   -      1       456  FALSE   TRUE    

Columns C-I contains single calculation steps, and column B contains the final formula with all substitutions.

Where is calculation failure?

4
  • Your macro seems to convert a "negative text number" to a real number, but I cannot get it to make it negative real number. I replaced <dash><hyphen> in your macro with two characters: -–. The first character is the hyphen/minus symbol from my MacBook keyboard, and the second is an the character which was in the data I pasted into Excel. I think it is an "em dash"? And yes, I did call the leading character a "hyphen" in my question, but I learned during testing another answer here that it's not a hyphen.
    – Seamus
    Aug 22, 2018 at 22:19
  • to continue: Am I missing something? Did I get the substitution wrong in your macro?
    – Seamus
    Aug 22, 2018 at 22:20
  • @Seamus Debugging added. Try. Did I get the substitution wrong in your macro? No. But I am afraid the symbols were "broken" when copypasted... Try to check them - look for a hyphen char code in source data.
    – Akina
    Aug 23, 2018 at 5:14
  • I'll try this as soon as I am able, and let you know the result.
    – Seamus
    Aug 23, 2018 at 10:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .