Advertisement
BugFix

Untitled

Apr 26th, 2014
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.83 KB | None | 0 0
  1. Sub Test_2()
  2.     Dim oMatch As Object
  3.     Dim iCount As Integer
  4.     Dim oCell As Range
  5.     Dim sPattern As String
  6.    
  7.     Set oCell = Application.ActiveCell
  8.     sPattern = "(\w*) (\d*)"
  9.    
  10.     iCount = SRE(oCell.Value, sPattern, oMatch)
  11.      
  12.     If iCount > 0 Then
  13.         oCell.Value = oMatch.Item(0).SubMatches.Item(0) & " == " & oMatch.Item(0).SubMatches.Item(1)
  14.     End If
  15.    
  16.     Set oMatch = Nothing
  17. End Sub
  18.  
  19. Function SRE(sString As Variant, sPattern As String, oResult As Object) As Integer
  20.     Dim oRegEx As Object
  21.      
  22.     Set oRegEx = CreateObject("VBscript.RegExp")
  23.     With oRegEx
  24.         .MultiLine = False
  25.         .Global = False
  26.         .IgnoreCase = True
  27.         .MultiLine = True
  28.         .Pattern = sPattern
  29.         Set oResult = .Execute(sString)
  30.     End With
  31.    
  32.     Set oRegEx = Nothing
  33.     SRE = oResult.Count
  34. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement