|
- Sub text()
- Dim reg As Object '声明
- Sheets(1).Copy After:=Sheets(1) '复制表1
- Sheets(2).Name = "结果"
- Sheets(2).Columns("F:L").Insert Shift:=xlShiftToRight '表2 插入7列
- Sheets(2).Range("F4:L4").ColumnWidth = 8.25
- Sheets(2).Cells(1, "f") = "JV"
- Sheets(2).Cells(1, "g") = "Account"
- Sheets(2).Cells(1, "h") = "CostCent"
- Sheets(2).Cells(1, "i") = "SalesC"
- Sheets(2).Cells(1, "j") = "ProjectC"
- Sheets(2).Cells(1, "k") = "Region"
- Sheets(2).Cells(1, "l") = "Market"
- arr = Sheets(3).Range("h2:h" & Sheets(3).UsedRange.Rows.Count) '表3 区号填入arr
- Set reg = CreateObject("VBScript.RegExp") '创建正则对象
- For I = 2 To Sheets(2).Cells(Rows.Count, 5).End(xlUp).Row '表2 e列循环
- a = Sheets(2).Cells(I, "e")
- With reg
- .Global = True
- .Pattern = "(\w+)-(\w+)-(\w+)-(\w+)-(\w+)-(\w+)-(\w+)-(\w+)-(\w+)"
- End With
- Set mat = reg.Execute(a)
- For Each m In mat '提取Account Combination 到FGHIJ
- Sheets(2).Cells(I, "f") = m.SubMatches(0)
- Sheets(2).Cells(I, "g") = m.SubMatches(1)
- Sheets(2).Cells(I, "h") = m.SubMatches(2)
- Sheets(2).Cells(I, "i") = m.SubMatches(4)
- Sheets(2).Cells(I, "j") = m.SubMatches(7)
- Next
- For j = LBound(arr, 1) To UBound(arr, 1) '表2h列匹配区号
- If arr(j, 1) = Sheets(2).Cells(I, "h").Value Then
- Sheets(2).Cells(I, "k") = Sheets(3).Cells(j + 1, "i")
- Sheets(2).Cells(I, "l") = Sheets(3).Cells(j + 1, "k")
- End If
- Next
- Next
- Set mat = Nothing
- End Sub
复制代码
|
评分
-
查看全部评分
|