Advertisement
felmoltor

Fix IP ranges Macro for Excel

Jan 17th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.88 KB | None | 0 0
  1. Sub Arregla_sintaxis_IP()
  2.     Dim cell As Range
  3.     Dim re As New RegExp
  4.     Dim DotsPositions(1 To 3) As Variant
  5.     Dim tmpstr As String
  6.     Dim cellstr As String
  7.            
  8.     With re
  9.         re.Pattern = "\d{10,12}"
  10.         re.IgnoreCase = True
  11.     End With
  12.    
  13.     For Each cell In Selection
  14.         tmpstr = ""
  15.         cellstr = CStr(cell)
  16.         ' En ese caso queremos meter una comillas (') delante y restaurar los puntos de los octetos
  17.         If re.Test(cellstr) Then
  18.             ' Convert to a string IP with dots
  19.             For i = Len(cellstr) To 1 Step -1
  20.                 tmpstr = Mid(cellstr, i, 1) & tmpstr
  21.                 If ((((i - 1) Mod 3) = 0) And (i <> 1)) Then
  22.                     tmpstr = "." & tmpstr
  23.                 End If
  24.             Next
  25.             tmpstr = "'" & tmpstr
  26.             cell.Value = tmpstr
  27.         End If
  28.     Next
  29. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement