+ Reply to Thread
Results 1 to 6 of 6

How do I remove comma and all decimals with vba/macro code

  1. #1
    Registered User
    Join Date
    05-11-2007
    Posts
    4

    How do I remove comma and all decimals with vba/macro code

    I get a report several times a week consisting of several columns and some hundred rows. There must be no comma signs in column E but the reports that I get will sometimes have commas in Col E anyway.

    I have a macro/vba code in another workbook that I start by a keyboard combination. This macro will adapt the look of the report, but it can't take care of the comma issue. However, I have managed to remove the comma and replace it with nothing but that is not sufficient. I want to delete the comma and all figures to the right of the comma sign. There can between 1 and 4 decimal numbers.

    I need to integrate some kind of vba code that will check every cell in column E and if it finds a comma in any cell, the comma must be deleted and all the numbers to the right of the comma too.

    Hope you can help me with this issue because I have been googling around for two days now... It drives me crazy.

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    Try with this code (it's an example to work on cells from e1 to e10):
    Please Login or Register  to view this content.
    I hope it can help.

    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    05-11-2007
    Posts
    4
    Thank you Antonio,

    The code that you provided works perfectly when there is only 1 or 2 decimals and that is great, but there is a problem when there are more than 2decimal numbers. When there are 3 or more decimals the code will remove the comma sign but not delete the decimal numbers and therefore the value of the cell will be significantly higher than it actually is. On some occasions the macro will not only remove the comma, but also remove all other numbers, except for the first number:

    132,1245 will be either 1321245 or only 1 on some occasions. I can't see any pattern when this happens.

    Hope you can help me to get the code working on numbers up to 4 decimals.

  4. #4
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    May be I didn't remember to add '.text'. Please try this code:
    Please Login or Register  to view this content.
    Regards,
    Antonio

  5. #5
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    You can also use this macro:
    Please Login or Register  to view this content.
    Regards,
    Antonio

  6. #6
    Registered User
    Join Date
    05-11-2007
    Posts
    4
    Thank you very much for your help.

    The code works fine now.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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