+ Reply to Thread
Results 1 to 17 of 17

How to extract capitalize letter text at certain position

Hybrid View

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

    Re: How to extract capitalize letter text at certain position

    Some miss-spelled customer and all in Caps, so can not recognize proper cust name.
    Sub test()
        Dim a, i As Long, temp As String, m As Object, dic As Object, Cust As String
        Set dic = CreateObject("Scripting.Dictionary")
        With Cells(1).CurrentRegion
            a = .Value
            a(1, 1) = "CUSTOMER": a(1, 2) = "DEBIT": a(1, 3) = "CREDIT"
            With CreateObject("VBScript.RegExp")
                .Pattern = ".*[a-z\d] ([A-Z]+( [A-Z]+)*)" & Chr(2) & "(.+) (DB|CR)$"
                For i = 2 To UBound(a, 1)
                    temp = Join(Array(a(i, 2), a(i, 4)), Chr(2))
                    a(i, 2) = "": a(i, 3) = ""
                    If .test(temp) Then
                        Set m = .Execute(temp)(0).submatches
                        Cust = m(0)
                        If Not dic.exists(Cust) Then
                            dic(Cust) = dic.Count + 2
                            a(dic(Cust), 1) = m(0)
                            a(dic(Cust), IIf(m(3) = "DB", 2, 3)) = m(2)
                        Else
                            a(dic(Cust), IIf(m(3) = "DB", 2, 3)) = a(dic(Cust), _
                            IIf(m(3) = "DB", 2, 3)) + Val(m(2))
                        End If
                    End If
                Next
            End With
            With .Offset(, .Columns.Count + 1).Resize(dic.Count + 1, 3)
                .Rows(1).Interior.Color = vbYellow
                With .CurrentRegion
                    .ClearContents: .Font.Bold = False
                    .Borders.LineStyle = xlNone
                End With
                .Value = a
                .Rows(1).Font.Bold = True
                .CurrentRegion.Sort .Cells(1), 1, , , , , , True
                With .Rows(.Rows.Count + 1)
                    .Value = Array("Total", "=sum(r2c:r[-1]c)", "=sum(r2c:r[-1]c)")
                    .Font.Bold = True: .Cells(1).HorizontalAlignment = xlRight
                End With
                .CurrentRegion.Borders.Weight = 2
                .EntireColumn.AutoFit
            End With
        End With
    End Sub
    Attached Files Attached Files

+ 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. Capitalize first letter of every word
    By Steve1960 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-17-2013, 04:41 PM
  2. Capitalize all first letter
    By CoachBarker in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 08-07-2013, 12:25 PM
  3. [SOLVED] Only Capitalize First Letter & Delete Last Name
    By zulhfreelancer in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 7
    Last Post: 12-11-2012, 02:16 AM
  4. [SOLVED] Capitalize first letter in a cell
    By oskie89 in forum Excel General
    Replies: 4
    Last Post: 07-31-2012, 06:48 PM
  5. Capitalize first letter
    By randall78 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-14-2012, 03:56 AM
  6. Capitalize first letter of every word
    By inspirone1505 in forum Excel General
    Replies: 5
    Last Post: 02-20-2007, 03:06 AM
  7. Replies: 7
    Last Post: 02-19-2007, 12:17 AM

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