MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Question regarding comparing integer as text

  Asked By: Trupti    Date: Mar 22    Category: MS Office    Views: 1779

The program I am writing now requires me to find a matching four
digits number to a alphbetical-numerical serial number that is provided
which inlude the number (and the entire number). E.g., Z0000, WPS0153,
QQ2346 and so on and so forth, so that 0000 is contained in Z0000 would
return true, and 0153 = WQS0053 would give false. Hopefully I am clear
enough here. :)
Now is the problem. I tried to make the Excel spreadsheet to take in
4 digits integers by specify the format to "0000". However, the value
shown in the formula bar, for 0000, is still 0, and hence, it would
return true for anything that contains the single digit 0, i.e., it
would return true for Z001 because it contains a 0 and return true to
Z0153 also because it contains a 0! That is far from what I want to do.
So I am wondering whether someone could come out with an VBA sub to
make my intended comparison work.



4 Answers Found

Answer #1    Answered By: Sebastian Anderson     Answered On: Mar 22

You need to stop Excel treating your string as a number. To do this, you will
need to format the input cell as "text" - before you type anything into it.

If you're using VBA for the comparison, you'll need to make sure that any
parameter or local variable this string is going into is defined as a string,
not a number.

Answer #2    Answered By: Inez Wood     Answered On: Mar 22

I was doing comparison in VBA, and what I did was to define a string

Answer #3    Answered By: Natasha Rivera     Answered On: Mar 22

Or you can typecast it at run time ..........

Answer #4    Answered By: Saila Iqbal     Answered On: Mar 22

No, I doubt that you can do this. I think you'll find  that Excel strips any
leading zeroes when you type them into a numeric cell. They're gone, and
typecasting will not bring them back.

Didn't find what you were looking for? Find more on Question regarding comparing integer as text Or get search suggestion and latest updates.