+ Reply to Thread
Results 1 to 3 of 3

Delete the last number if the number format is *.***

Hybrid View

  1. #1
    Registered User
    Join Date
    07-28-2013
    Location
    Athens
    MS-Off Ver
    Excel 2010
    Posts
    55

    Lightbulb Delete the last number if the number format is *.***

    Hello everyone and happy new year.....


    I have a problem that breaks my brain for a lot of days now.

    I have this data on my excel file in "A" Column:

    UD Maracena vs Guadix 27/12/2015 12:45
    2.666
    3.20
    2.45
    (+97) Atletico Sanluqueno CF vs Coria CF 27/12/2015 13:00
    1.75
    3.50
    4.20
    (+95) CD Ronda vs Atletico Mancha Real 27/12/2015 13:00
    4.333
    3.80
    1.666
    (+96) CD San Roque de Cadiz vs CD herena 27/12/2015 13:00
    2.00
    3.40
    3.40

    Before I convert my data with a big macro, I want to delete the last number of every cell that is in format "0.000" I want to make it like this: "0.00" and change it to "General" format and keep the dot "."

    So:
    1: Delete the last number of every cell that is "*.***" and make it "*.**"
    2: Change the format of those cells to "General"
    3: Keep the dot (because every time I change those cells to general format, I lose the dot)

    I use excel 2013.
    This is my test file: dot.xlsm

    Please help me with that, thanks everyone and I wish the best for 2016...
    Last edited by lagiosman; 12-30-2015 at 11:23 AM.
    ~Our technology has exceeded our humanity~

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

    Re: Delete the last number if the number format is *.***

    If you want to convert 2,666 or 2.666 to 2.66 then try
    Sub test()
        Dim r As Range, temp
        With CreateObject("VBScript.RegExp")
            .Pattern = "(\d+)[,.](\d{2})\d*"
            For Each r In Range("a1", Range("a" & Rows.Count).End(xlUp))
                If .test(r.Text) Then
                    temp = r.Text
                    r.NumberFormat = "0.00"
                    r.Value = .Replace(temp, "$1.$2")
                End If
            Next
        End With
    End Sub

  3. #3
    Registered User
    Join Date
    07-28-2013
    Location
    Athens
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Delete the last number if the number format is *.***

    Quote Originally Posted by jindon View Post
    If you want to convert 2,666 or 2.666 to 2.66 then try
    Sub test()
        Dim r As Range, temp
        With CreateObject("VBScript.RegExp")
            .Pattern = "(\d+)[,.](\d{2})\d*"
            For Each r In Range("a1", Range("a" & Rows.Count).End(xlUp))
                If .test(r.Text) Then
                    temp = r.Text
                    r.NumberFormat = "0.00"
                    r.Value = .Replace(temp, "$1.$2")
                End If
            Next
        End With
    End Sub
    Thank you very much , it works, thanks.....

+ 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. Need formula or code to convert number(s) from custom format to number format
    By tuongtu3 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-12-2015, 07:44 PM
  2. [SOLVED] formula to auto delete number in dropdown list when number appears in another cell #2
    By ddevins in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-28-2014, 08:31 AM
  3. [SOLVED] formula to auto delete number in dropdown list when number appears in another cell
    By ddevins in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 04-28-2014, 04:54 AM
  4. [SOLVED] If text the delete, if number then copy number to another cell
    By exchangejames in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-22-2013, 10:01 AM
  5. Unable to insert row or delete row or erase values-macro-Indian number format
    By srinivasan1965 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-16-2012, 07:12 AM
  6. Replies: 1
    Last Post: 05-18-2006, 11:45 PM
  7. Number format based on number format of another cell in another workbook
    By Rob in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-09-2005, 01:06 PM

Tags for this Thread

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