Results 1 to 4 of 4

Colouring variable text within a cell / string, and merging a variable number of cells

Threaded View

Steve M. Colouring variable text... 02-16-2015, 06:14 PM
Steve M. Re: Colouring variable text... 02-17-2015, 10:41 AM
LJMetzger Re: Colouring variable text... 02-17-2015, 06:17 PM
jindon Re: Colouring variable text... 02-17-2015, 11:53 PM
  1. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Colouring variable text within a cell / string, and merging a variable number of cells

    Try the attached
    Sub test()
        Dim a, i As Long, pref As String, e
        Dim rng As Range, r As Range, mtch As Object, m As Object, s As Object
        a = Cells(1).CurrentRegion.Value
        a(1, 3) = "Status / Due Date"
        With CreateObject("Scripting.Dictionary")
            For i = 2 To UBound(a, 1)
                If a(i, 3) = "Closed" Then
                    pref = a(i, 3) & ", Completed "
                Else
                    pref = IIf(a(i, 4) < Date, "Over ", "") & "Due, "
                End If
                If Not .exists(a(i, 1)) Then
                    .Item(a(i, 1)) = .Count + 2
                    a(.Item(a(i, 1)), 1) = a(i, 1)
                    a(.Item(a(i, 1)), 2) = "1. " & a(i, 2)
                    a(.Item(a(i, 1)), 3) = "1. " & pref & Format$(a(i, 4), "yyyy/m/d")
                    a(.Item(a(i, 1)), 4) = 1
                Else
                    a(.Item(a(i, 1)), 4) = a(.Item(a(i, 1)), 4) + 1
                    a(.Item(a(i, 1)), 2) = a(.Item(a(i, 1)), 2) & vbLf & _
                    a(.Item(a(i, 1)), 4) & ". " & a(i, 2)
                    a(.Item(a(i, 1)), 3) = a(.Item(a(i, 1)), 3) & vbLf & _
                    a(.Item(a(i, 1)), 4) & ". " & pref & Format$(a(i, 4), "yyyy/m/d")
                End If
            Next
            i = .Count
        End With
        Set rng = [g1].Resize(i + 1, 3)
        rng.Clear
        rng.Value = a
        With CreateObject("VBScript.RegExp")
            .Global = True: .MultiLine = True
            For Each r In rng.Columns(3).Cells
                For Each e In Array("Completed", "Over Due")
                    .Pattern = "^(\d+).+" & e & ".+"
                    If .test(r.Value) Then
                        Set mtch = .Execute(r.Value)
                        For Each m In mtch
                            .Pattern = "^" & m.submatches(0) & ".+"
                            Set s = .Execute(r(, 0).Value)(0)
                            r.Characters(m.firstindex + 1, m.Length).Font.ColorIndex = _
                            Switch(e = "Completed", 15, e = "Over Due", 3)
                            r(, 0).Characters(s.firstindex + 1, s.Length).Font.ColorIndex = _
                            Switch(e = "Completed", 15, e = "Over Due", 3)
                        Next
                    End If
                Next
            Next
        End With
    End Sub
    Attached Files Attached Files
    Last edited by jindon; 02-18-2015 at 01:34 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Sum individual day's data but merging variable number of cells problem.
    By skyping in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-26-2015, 04:17 PM
  2. [SOLVED] Calculate average of variable number of cells variable number of times
    By WeirnetherlandsBart in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-06-2014, 10:11 AM
  3. [SOLVED] Need to use a text string from another cell as a variable range in another equation.
    By herbie226 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-05-2014, 06:17 PM
  4. Replies: 4
    Last Post: 07-12-2013, 12:14 PM
  5. Merging the correct number of cell rows to fit a string of wrapped text
    By iterature in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-28-2007, 02:15 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