+ Reply to Thread
Results 1 to 5 of 5

Replacing - with . macro

Hybrid View

  1. #1
    Registered User
    Join Date
    04-29-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    92

    Replacing - with . macro

    I have numbers in column A (The number of rows will vary) that are in this format:
    0000-000-000

    I want them to be in this format:
    0000000.000

    I've tried several macros with no luck.

    Thanks in Advance!

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: Replacing - with . macro

    Try this, and apply custom format

    0.000

    to the results. This puts the results in column B so you don't lose the original data. If you want to overwrite the original data, change "B" to "A".

    Private Sub test()
    
       Dim R As Long
       Dim S As String
       R = 1
       Do Until Cells(R, "A") = ""
          S = Cells(R, "A")
          Cells(R, "B") = Left(S, 4) & Mid(S, 6, 3) & "." & Right(S, 3)
          R = R + 1
       Loop
    
    End Sub
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    06-04-2019
    Location
    U.S.
    MS-Off Ver
    2016
    Posts
    48

    Re: Replacing - with . macro

    Ms. Alesha,

    Good morning and hello again!! Might try something like this:

    Sub changeFormat()
    
    Dim x As Integer
    Dim lastRow as Long
    
    lastRow = Range("A95000").End(xlUp).Row
    
    For x = 1 To lastRow
    
         If Range("A" & x).Value Like "####-###-###" Then
    
              Range("A" & x).Value = Format(Range("A" & x).Value, "#######.###")
    
         End If
    
    Next x
    
    End Sub
    Hope this helps!!

    Dome

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

    Re: Replacing - with . macro

    Replace the last hyphen with a period.
    Sub test()
        Dim a, i As Long
        With Range("a1", Range("a" & Rows.Count).End(xlUp))
            a = .Value
            For i = 1 To UBound(a, 1)
                If a(i, 1) Like "*-*" Then
                    a(i, 1) = "'" & Replace(Application.Replace(a(i, 1), InStrRev(a(i, 1), "-"), 1, "."), "-", "")
                End If
            Next
            .Value = a
        End With
    End Sub

  5. #5
    Registered User
    Join Date
    04-29-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    92

    Re: Replacing - with . macro

    Thanks everyone! Works great!

+ 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. [SOLVED] Looking for a replacing macro
    By wonderd in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-12-2016, 05:21 PM
  2. Replacing strings/ replacing numbers and letters
    By Insert Name in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2015, 01:15 PM
  3. Replace method in macro - Macro not replacing all occurrences
    By slw_gen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-19-2011, 06:57 PM
  4. Macro for Replacing Characters
    By jones1000 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-02-2011, 04:17 PM
  5. Replacing strings within macro's
    By tneva in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-05-2009, 08:55 AM
  6. replacing macro?
    By beatrice25 in forum Excel General
    Replies: 4
    Last Post: 06-20-2006, 08:33 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