Purple_Squirrel
New Member
- Joined
- May 8, 2019
- Messages
- 7
Hi,
I have an excel sheet full of IP Addresses along with their descriptions in adjacent cells like 192.168.1.1 ABC, 192.168.1.2 XYZ.....etc what I am trying to do is to extract all of these IP Addresses along with their descriptions from a worksheet and write them to another worksheet in adjacent columns like:
192.168.1.1 ABC
192.168.1.2 XYZ and so on.
I apologize for the fact that I am not good at VB Script and not much idea how to accomplish this. I have have attempted to use the following VB Script gotten from one of the threads:
Sub blah()
'Set MasterSpreadsheet = ("D:\\Test.xls")
For Each sht In ThisWorkbook.Sheets
If Application.CountA(sht.Cells) > 0 Then
i = 1
ReDim Results(1 To 1)
With sht.Cells
Set c = .Find(what:="*?.?*.?*.?*", Lookat:=xlPart, LookIn:=xlFormulas)
If Not c Is Nothing Then
firstAddress = c.Address
Do
zzz = ExtractIPs(c.Value)
If Len(zzz) > 0 Then
ReDim Preserve Results(1 To i)
Results(i) = zzz
i = i + 1
' Application.Goto c
' MsgBox "here! " & vbLf & zzz
End If
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
.Cells(.Rows.Count, "AD").End(xlUp).Offset(1).Resize(UBound(Results)) = Application.Transpose(Results)
' With MasterSpreadsheet
' Set Destn = .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Resize(UBound(Results))
' Destn = Application.Transpose(Results)
' Destn.Offset(, 1) = "from sheet " & sht.Name
' End With 'MasterSpreadsheet
End With 'sht.Cells
End If
Next sht
End Sub
Function ExtractIPs(s As String)
With CreateObject("VBScript.RegExp")
.Pattern = "[\s\S]*?(\d{1,3}(\.\d{1,3}){3})|[\s\S]*"
.Global = True
ExtractIPs = Replace(Trim(.Replace(s, " $1")), " ", ", ")
End With
End Function
I would be extremely appreciative if someone would help me with what I am trying to do. Thank you.
I have an excel sheet full of IP Addresses along with their descriptions in adjacent cells like 192.168.1.1 ABC, 192.168.1.2 XYZ.....etc what I am trying to do is to extract all of these IP Addresses along with their descriptions from a worksheet and write them to another worksheet in adjacent columns like:
192.168.1.1 ABC
192.168.1.2 XYZ and so on.
I apologize for the fact that I am not good at VB Script and not much idea how to accomplish this. I have have attempted to use the following VB Script gotten from one of the threads:
Sub blah()
'Set MasterSpreadsheet = ("D:\\Test.xls")
For Each sht In ThisWorkbook.Sheets
If Application.CountA(sht.Cells) > 0 Then
i = 1
ReDim Results(1 To 1)
With sht.Cells
Set c = .Find(what:="*?.?*.?*.?*", Lookat:=xlPart, LookIn:=xlFormulas)
If Not c Is Nothing Then
firstAddress = c.Address
Do
zzz = ExtractIPs(c.Value)
If Len(zzz) > 0 Then
ReDim Preserve Results(1 To i)
Results(i) = zzz
i = i + 1
' Application.Goto c
' MsgBox "here! " & vbLf & zzz
End If
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
.Cells(.Rows.Count, "AD").End(xlUp).Offset(1).Resize(UBound(Results)) = Application.Transpose(Results)
' With MasterSpreadsheet
' Set Destn = .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Resize(UBound(Results))
' Destn = Application.Transpose(Results)
' Destn.Offset(, 1) = "from sheet " & sht.Name
' End With 'MasterSpreadsheet
End With 'sht.Cells
End If
Next sht
End Sub
Function ExtractIPs(s As String)
With CreateObject("VBScript.RegExp")
.Pattern = "[\s\S]*?(\d{1,3}(\.\d{1,3}){3})|[\s\S]*"
.Global = True
ExtractIPs = Replace(Trim(.Replace(s, " $1")), " ", ", ")
End With
End Function
I would be extremely appreciative if someone would help me with what I am trying to do. Thank you.