+ Reply to Thread
Results 1 to 13 of 13

Macro to convert specific text and format specific text within a string

Hybrid View

Mencae Macro to convert specific... 12-04-2012, 04:23 PM
gyclone Re: Macro to convert specific... 12-04-2012, 05:36 PM
Mencae Re: Macro to convert specific... 12-04-2012, 06:27 PM
gyclone Re: Macro to convert specific... 12-04-2012, 05:42 PM
gyclone Re: Macro to convert specific... 12-04-2012, 07:03 PM
jindon Re: Macro to convert specific... 12-04-2012, 07:41 PM
Mencae Re: Macro to convert specific... 12-05-2012, 01:26 PM
gyclone Re: Macro to convert specific... 12-04-2012, 08:00 PM
jindon Re: Macro to convert specific... 12-04-2012, 08:18 PM
gyclone Re: Macro to convert specific... 12-05-2012, 01:39 PM
Mencae Re: Macro to convert specific... 12-05-2012, 01:48 PM
jindon Re: Macro to convert specific... 12-05-2012, 02:59 PM
Mencae Re: Macro to convert specific... 12-06-2012, 12:13 AM
  1. #1
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Macro to convert specific text and format specific text within a string

    Different method
    Option Explicit
    
    Sub test()
        Dim r As Range, temp, num
        Const div As Double = 22.046
        With CreateObject("VBScript.RegExp")
            For Each r In Range("a1", Range("a" & Rows.Count).End(xlUp))
                If r.Value Like "*USD/MT" Then
                    r.Value = Replace(r.Value, "USD/MT", "USC/LB")
                    .Pattern = "(\+|\-)(\d+(\.\d+))"
                    If .test(r.Value) Then
                        num = Format$(Round(CDbl(.Execute(r.Value)(0).submatches(1)) / div, 2), "#.0000")
                        r.Value = .Replace(r.Value, .Execute(r.Value)(0).submatches(0) & num)
                        r.Characters(1, 2).Font.Bold = True
                        r.Characters(.Execute(r.Value)(0).firstindex + 2, _
                        .Execute(r.Value)(0).Length - 1).Font.Color = vbRed
                    End If
                    .Pattern = "USC/LB"
                    r.Characters(.Execute(r.Value)(0).firstindex + 1, .Execute(r.Value)(0).Length).Font.Bold = True
                End If
            Next
        End With
    End Sub
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    08-12-2010
    Location
    Austin, Tx
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Macro to convert specific text and format specific text within a string

    Very Cool! I can see I'm out of my league here! LOL But, I have a renewed interest in coding again.

    This works great if the data is in column "A" what if the data appears in multiple columns (not always the same each time)? How would you modify this to execute on any column in the active worksheet?

    I apologize for being such a noob

    Thanks again

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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