20170624xlVBA Regular Segmentation subtotals

Source: Internet
Author: User

Sub regexpsubtotal () ' Declare variable Dim Regex As Object ' regular object Dim Dic As Object ' Dictionary object Dim key As String ' keyword Dim Ite M as Double ' contents Dim Index As Long ' ordinal Dim text As String ' text Dim Mch As Object ' match set Dim onemch As Object ' match subkey Dim Rng as Range ' Cell object ' instantiation of regular object and Dictionary object Set Regex = CreateObject ("VBScript.RegExp") Set Dic = Createobje CT ("Scripting.Dictionary") with Regex. Global = True ' matching mode Zhejiang 4000 Anhui 19963.78 pattern = "([^\d\.] +) ([\d\.] +)"        . Pattern = pattern End with ' line-by-loop ' payment details for Index = 2 to Cells (Cells.Rows.Count, 1). End (Xlup). Row Text = Cells (Index, "A"). Text ' get literal set Mch = Regex.execute (text) ' Execute match for each onemch in Mch ' Loop match set Key = O        Nemch.submatches (0) ' Customer name Item = CDBL (onemch.submatches (1)) ' Payment amount dic (key) = DIC (key) + Item ' Subtotal Next onemch next Index ' quick transpose output subtotal content Set Rng = Range ("C1"). Resize (Dic.count, 2) Rng.Value = Application.WorksheetFunction.Transpose (Array (Dic.keys, Dic.items)) ' Release object Set Regex = Nothing Set Dic = Nothing Set Rng = NothingEnd Sub

  

20170624xlVBA Regular Segmentation subtotals

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.