Forcing Excel to interpret number as text

Gates Is Antichrist

Well-known Member
Joined
Aug 15, 2002
Messages
1,961
This is a restart of http://www.mrexcel.com/board2/viewtopic.php?t=130209&postdays=0&postorder=asc&start=0 which grew long but didn't solve the issue. Perhaps this is related to the old dilemma of trying to preserve trailing zeroes?

Imported cell A1 is
=4-6
I cannot figure out how to stop Excel from performing the math. I want to parse out the 4 and 6, but Excel changes it to minus 2.

C1 ="X" & A1
gives X-2

Formatting C1 as text causes it to look like
="X" & A1
(that's actually what's displayed - it even treats the equal sign as text).
This still doesn't give me the 4 and 6 to work with.

Other things I've tried all perform the subtraction. Even MID(A1,1,1) returns "-" - CHEEEEZ!! *** Even if the cells I paste to are formatted as text *** before the paste, there are still cases where Excel "helps" me by making a date or performing subtraction:

Try this test:
format a new sheet's cells A1 to C3 as text;
scrape-copy only the 3 characters 4-6 on this line in this message with Ctl-C;
Ctl-V to A1. Nasty, huh? Are the 4 and the 6 lost forever then?

The Death Example:
Take http://mlb.mlb.com/NASApp/mlb/mlb/standings/index.jsp and scrape and ctl-C the 5 line rectangle, starting your scrape with the left edge of the letter N in New York, through the end of the Toronto line. Paste into a virgin worksheet (general format). You'll see that some cells became dates, and it seems that original data is unreachable. This also happens when the virgin sheet is first converted to text format cells. The (e.g.) 10 and minus and 22 seem to be beyond the grasp of retrievability.

Sorry for the length here, but this greatly condenses the long thread referenced atop. There were fine and sound posts there, but didn't defeat the failure of the examples I just stated.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
please ignore if you've tried this (maybe I don't quite understand your problem, I didn't go back to your old posts), in any case, just put a single ' before the 4-6 in cell A1. This prevents excel from seeing it as numbers (much more effectively than formatting as text).
 
Upvote 0
Workaround for the second problem:
Paste as text in column A, all data from one row will be in one cell
column B: = SUBSTITUE(A1," "," '")
Copy col B and paste values
then text to columns

does this help?
it could give some ideas for the first problem ...

the first problem
kind regards,
Erik
 
Upvote 0
Okay, paste special as text, it is. I resisted this because of all the extra work needed to parse it, but that's the only way anyone's shown to stop the Microsoft "courtesy" of performing the evaluation. (Note: I'm using the SUBSTITUTE suggested above, though I don't know what it buys me, vs. just parsing on space itself.)

The following steps, if anyone's interested (or has something better), are (with the "ugly" text data imported to A1:A5):

A7=0
A8=A7+1 (copy this downward)

B1=SUBSTITUTE(A1," "," '")
B6=0
B7=FIND("'",$B$1,B6+1) (copy this downward)

C8=MID($B$1,B7+1,B8-B7-1) (copy this downward)

That gives a vertical parsing, which I'd reorient to have the each parsed data group aside its text source.

Alternatively, I may use VBA with
Range("A1").TextToColumns Destination:=Range("B1"), DataType:=xlDelimited,ConsecutiveDelimiter:=True,Space:=True, FieldInfo:=Array(Array(1,1),Array(2,1),Array(3,1),Array(4,1), Array(5,1),Array(6,1),Array(7,1),Array(8,1),Array(9,1),Array(10,1),Array(11,1),Array(12,1),Array(13,1),Array(14,1),Array(15,1))
I'll have to manage looping this (with a variable number of rows, naturally) and other details.

Either way requires me to rely on space as a pure delimiter. I'm sure that's going to fall apart and destroy me. Gaaaaates!!

I quite seriously considered doing a regular paste and using ISDATE and reversing out any dates. However, there's no such animal - dates are actually numeric.

Thanks for the effort all have made, although I'm disappointed that there wasn't a clean way just to get Excel to leave each cell as text. What a PITA!! And needlessly so! Gaaaaaates!!
 
Upvote 0
Alisa, thank you for your suggestion, which was valid. The only reason is doesn't help me is because in this circumstance, there seems to be no way to automate it, and I don't relish manually adjusting each line of data. Otherwise, that is a handy tip.
 
Upvote 0
Again, thanks. As it happens, preformatting destination cells as text seems to alternatively accomplish what you describe.
 
Upvote 0
Well, not quite. It doesn't stop Excel from having already turned such cells to dates before I get there, so it seems the nasty parse is needed, for the problem at hand.

Again, thanks. As it happens, preformatting destination cells as text seems to accomplish what you describe, but what you describe may in some cases become handy as an alternative. Actually, I kind of prefer seeing the explicit ' rather than hoping that a cell is formatted properly, so your idea may really rock the next time I have the need.
 
Upvote 0

Forum statistics

Threads
1,216,045
Messages
6,128,477
Members
449,455
Latest member
jesski

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top