+ Reply to Thread
Results 1 to 17 of 17

Formatting numbers and formulas as text doesn't really work

  1. #1
    Registered User
    Join Date
    08-12-2013
    Location
    Israel
    MS-Off Ver
    Excel 2003
    Posts
    58

    Formatting numbers and formulas as text doesn't really work

    Hi,
    I have some text that also contains numbers with a decimal point. I am trying to remove all the digits from the text using the replace function. Although the entire data range is formatted as text, I cannot remove the digit just left of the decimal point. If it's a 0, nothing happens, if it's another digit it is changed into 0.
    I am using a macro, but I have the same problem when working directly with Excel's functions.
    What should I do?
    Thanks,
    Chen
    Last edited by chengafni; 10-01-2017 at 06:29 AM. Reason: the scope of the problem is more general than defined initially

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,767

    Re: Formatting numbers as text doesn't really work

    Post a sample of your workbook for analysis. Include also your VBA attempt.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    08-12-2013
    Location
    Israel
    MS-Off Ver
    Excel 2003
    Posts
    58

    Re: Formatting numbers and formulas as text doesn't really work

    Ok, take a look at the sample data.
    Please try the following:
    - Replace all 3s with nothing: 3 in the first cell is changed into 0.
    - Replace all 0s with nothing: Excel announces that 2 replacements have been made, in reality nothing happens.
    - Replace all a's with nothing: Excel announces a problem with a formula and leaves the 'a' in the last cell.

    The code in the attached file produces the same results.
    Attached Files Attached Files
    Last edited by chengafni; 10-01-2017 at 06:29 AM. Reason: the scope of the problem is more general than defined initially

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,767

    Re: Formatting numbers and formulas as text doesn't really work

    When I run the code, I get the following. What are your expected results supposed to be?

    Data Range
    A
    1
    0.5
    2
    0.441628
    3
    4
    -19
    5
    v
    6
    1948
    7
    c
    8
    a=>

  5. #5
    Registered User
    Join Date
    08-12-2013
    Location
    Israel
    MS-Off Ver
    Excel 2003
    Posts
    58

    Re: Formatting numbers and formulas as text doesn't really work

    I got the same results. The desired results would be:

    Row 1: .5
    Row 2: .441628
    Row 8: =>

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Formatting numbers and formulas as text doesn't really work

    1) should be vbNullString

    Try
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-12-2013
    Location
    Israel
    MS-Off Ver
    Excel 2003
    Posts
    58

    Re: Formatting numbers and formulas as text doesn't really work

    Thank you and sorry about the typo in the code.
    This is not exactly what I had in mind. I am trying to remove characters one at a time, and I want Excel to really treat EVERYTHING as text. I don't understand why formatting cells as text doesn't achieve that.

  8. #8
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Formatting numbers and formulas as text doesn't really work

    Try formula
    Enter in B1 and copy down
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    v A B
    1 3.5 .5
    2 0.44162777 .441628
    3 a
    4 -19
    5 v
    6 1948
    7 c
    8 a=> =>
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Formatting numbers and formulas as text doesn't really work

    Quote Originally Posted by chengafni View Post
    I don't understand why formatting cells as text doesn't achieve that.
    Because excel cell has "auto-casting" functionality, so as soon as refreshed by the Replace method, the cell recognise it as NUMBER no matter how you change the format.
    Also = sign at the beginning.
    It will tread as a Formula so can't be replaced.

  10. #10
    Registered User
    Join Date
    08-12-2013
    Location
    Israel
    MS-Off Ver
    Excel 2003
    Posts
    58

    Re: Formatting numbers and formulas as text doesn't really work

    Thank you all, I really appreciate your willingness and effort.
    Your proposals are rather specific to the examples I provided. I am looking for a global solution that will enable me to remove specific characters from an entire range. From your responses I get that there isn't one.

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Formatting numbers and formulas as text doesn't really work

    You are welcome and good luck in finding the solution with REPLACE method in years...

  12. #12
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Formatting numbers and formulas as text doesn't really work

    Quote Originally Posted by chengafni View Post
    Thank you all, I really appreciate your willingness and effort.
    Your proposals are rather specific to the examples I provided. I am looking for a global solution that will enable me to remove specific characters from an entire range. From your responses I get that there isn't one.
    Hmm... You want to remove "specific characters" but you never mentioned what those characters are? Can you list those very special characters?

  13. #13
    Registered User
    Join Date
    08-12-2013
    Location
    Israel
    MS-Off Ver
    Excel 2003
    Posts
    58

    Re: Formatting numbers and formulas as text doesn't really work

    well, I have a very long text that contains all sorts of irrelevant characters. I have a list of about 30 characters (or basically any list that the user wishes). I wrote a macro that is supposed to delete all but those 30 characters from the text. It works most of the time, but fails in specific cases as those mentioned above.
    Interestingly, when a character happens to appear in a string that Excel identifies as a formula (e.g., a in a=>), trying to remove the character (e.g., a) leads to an "error in formula" and as a result Excel stops the replacing process and leaves all the remaining instances of the character untouched.

  14. #14
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Formatting numbers and formulas as text doesn't really work

    The only logic I see here is that you want this special formatting to be applied only to the numbers with decimals and everything else with an exception of "=>" to be ignored.
    Try this modified formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    or a little bit shorter
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by AlKey; 10-01-2017 at 12:29 PM.

  15. #15
    Registered User
    Join Date
    08-12-2013
    Location
    Israel
    MS-Off Ver
    Excel 2003
    Posts
    58

    Re: Formatting numbers and formulas as text doesn't really work

    Ok, thank you very much!

  16. #16
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Formatting numbers and formulas as text doesn't really work

    Hi,

    You might also use an array instead of the Range.Replace method
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  17. #17
    Registered User
    Join Date
    08-12-2013
    Location
    Israel
    MS-Off Ver
    Excel 2003
    Posts
    58

    Re: Formatting numbers and formulas as text doesn't really work

    Yes, that does the job. Thank you very much! (and also for solving the other thread).

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro doesn't work with floating point numbers
    By DNQT in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-14-2012, 03:36 PM
  2. Excel 2007 : AND doesn't work in Conditional Formatting
    By cellarir in forum Excel General
    Replies: 2
    Last Post: 03-21-2012, 06:10 PM
  3. SUMIFS asterisk on numbers doesn't work
    By n748 in forum Excel General
    Replies: 3
    Last Post: 06-30-2010, 07:49 AM
  4. [SOLVED] Need to reconcile numbers accounting Harlan Grove code doesn't work for negative numbers
    By aep002@cox.net in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-28-2006, 02:15 AM
  5. Need to reconcile numbers accounting Harlan Grove code doesn't work for negative numbers
    By aep002@cox.net in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-27-2006, 10:15 PM
  6. Sorting numbers doesn't work correctly
    By GrammyEmmy in forum Excel - New Users/Basics
    Replies: 8
    Last Post: 06-25-2006, 06:50 PM
  7. Entering numbers - doesn't work right
    By Zzilly14 in forum Excel General
    Replies: 2
    Last Post: 04-23-2006, 09:10 PM
  8. IF formula doesn't work with certain numbers
    By kaywe44 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-10-2006, 04:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1