Advertisement
BugFix

Untitled

Apr 25th, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.97 KB | None | 0 0
  1. Sub Swap_Coordinate() 'v1.0 coded by UEZ
  2.     Dim RegExsult As String
  3.     Dim allMatches As Object
  4.     Dim innerMatches As Object
  5.     Dim RegEx As Object 'New VBScript_RegExp_55.RegExp 'Tools -> References -> Microsoft VBScript Regular Expression 5.5
  6.     Set RegEx = CreateObject("VBScript.RegExp")
  7.     Dim iMultiLine As Integer
  8.     Dim iCurrent As Integer
  9.     RegExsult = ""
  10.     iCurrent = 0
  11.    
  12.     RegEx.Pattern = "(\n)"
  13.     RegEx.Global = True
  14.     RegEx.IgnoreCase = True
  15.     Set allMatches = RegEx.Execute(ActiveCell.Text)
  16.     iMultiLine = allMatches.Count
  17.    
  18.     If iMultiLine = 0 Then
  19.         RegEx.Pattern = "(.*) to (.*)"
  20.         Set allMatches = RegEx.Execute(ActiveCell.Text)
  21.         If allMatches.Count > 0 Then
  22.             RegExsult = allMatches.Item(0).subMatches.Item(1) & " to " & allMatches.Item(0).subMatches.Item(0) & " " & allMatches.Item(0).subMatches.Item(2)
  23.             ActiveCell.Value = RegExsult
  24.         End If
  25.     Else
  26.         RegEx.Pattern = "(.*)\n?"
  27.         Set allMatches = RegEx.Execute(ActiveCell.Text)
  28.         Do While iCurrent <= iMultiLine
  29.             If RegExsult <> "" Then
  30.                 RegExsult = RegExsult & Chr(13) & Chr(10)
  31.             End If
  32.             RegEx.Pattern = "(.*) to (.*)( free .*)"
  33.             Set innerMatches = RegEx.Execute(allMatches.Item(iCurrent))
  34.             If innerMatches.Count = 0 Then
  35.                 RegEx.Pattern = "(.*) to (.*)"
  36.                 Set innerMatches = RegEx.Execute(allMatches.Item(iCurrent))
  37.                 RegExsult = RegExsult & innerMatches.Item(0).subMatches.Item(1) & " to " & innerMatches.Item(0).subMatches.Item(0)
  38.             Else
  39.                 RegExsult = RegExsult & innerMatches.Item(0).subMatches.Item(1) & " to " & innerMatches.Item(0).subMatches.Item(0) & innerMatches.Item(0).subMatches.Item(2)
  40.             End If
  41.             iCurrent = iCurrent + 1
  42.         Loop
  43.         ActiveCell.Value = RegExsult
  44.     End If
  45.    
  46.     Set allMatches = Nothing
  47.     Set innerMatches = Nothing
  48.     Set RegEx = Nothing
  49. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement