Advertisement
BugFix

Untitled

Apr 25th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.85 KB | None | 0 0
  1. Sub Test()                        '  macht aus "ABC 123" --> "ABC == 123"
  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.     StringRegExp oCell.Value, sPattern, oMatch
  11.     iCount = oMatch.Count
  12.      
  13.     If iCount > 0 Then
  14.         oCell.Value = oMatch.Item(0).SubMatches.Item(0) & " == " & oMatch.Item(0).SubMatches.Item(1)
  15.     End If
  16.    
  17.     Set oMatch = Nothing
  18. End Sub
  19.  
  20.  
  21. Sub StringRegExp(sString As Variant, sPattern As String, oResult As Object)
  22.     Dim oRegEx As Object
  23.      
  24.     Set oRegEx = CreateObject("VBscript.RegExp")
  25.     With oRegEx
  26.         .MultiLine = False
  27.         .Global = False
  28.         .IgnoreCase = True
  29.         .MultiLine = True
  30.         .Pattern = sPattern
  31.         Set oResult = .Execute(sString)
  32.     End With
  33. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement