List IP's in a list of ranges

Danny54

Active Member
Joined
Jul 3, 2019
Messages
295
Office Version
  1. 365
Platform
  1. Windows
Does anyone know how to go about generating a list of ip's in list of ranges or seen it done using a macro?

Thanks

input sheet

test210.10.3.0-10.10.3.9, 10.10.3.11, 10.10.3.15-10.10.3.16
test3199.10.3.0-199.10.3.9, 199.10.3.11, 199.10.3.15-199.10.3.16

desired output sheet

10.10.3.0
10.10.3.1
10.10.3.2
10.10.3.3
10.10.3.4
10.10.3.5
10.10.3.6
10.10.3.7
10.10.3.8
10.10.3.9
10.10.3.11
10.10.3.15
10.10.3.16
199.10.3.0
199.10.3.1
199.10.3.2
199.10.3.3
199.10.3.4
199.10.3.5
199.10.3.6
199.10.3.7
199.10.3.8
199.10.3.9
199.10.3.11
199.10.3.15
199.10.3.16
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Your data from the input sheet "Sheet1" like this:
varios 11abr2020.xlsm
AB
1
2test210.10.3.0-10.10.3.9, 10.10.3.11, 10.10.3.15-10.10.3.16
3test3199.10.3.0-199.10.3.9, 199.10.3.11, 199.10.3.15-199.10.3.16
Sheet1

The output on sheet 2 in column A

Try this:

VBA Code:
Sub List_IPs()
  Dim c As Range, n As Long, j As Long, fin As Long
  Dim a As Variant, b As Variant, d() As Variant
  '
  For Each c In Sheets("Sheet1").Range("B2", Sheets("Sheet1").Range("B" & Rows.Count).End(3))
    For Each a In Split(c, ",")
      b = Split(a, "-")
      If UBound(b) = 0 Then fin = Mid(b(0), InStrRev(b(0), ".") + 1) Else fin = Mid(b(1), InStrRev(b(1), ".") + 1)
      For j = Mid(b(0), InStrRev(b(0), ".") + 1) To fin
        ReDim Preserve d(n)
        d(n) = Trim(Left(b(0), InStrRev(b(0), ".")) & j)
        n = n + 1
      Next j
    Next a
  Next c
  Sheets("Sheet2").Range("A2").Resize(n).Value = Application.Transpose(d)
End Sub
 
Upvote 0
just for fun, another approach with Power Query
Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table7"]}[Content],
    Trim = Table.TransformColumns(Table.ExpandListColumn(Table.TransformColumns(Source, {{"raw", Splitter.SplitTextByAnyDelimiter({",","-"}, QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "raw"),{{"raw", Text.Trim, type text}})
in
    Trim
rawraw
10.10.3.0-10.10.3.9, 10.10.3.11, 10.10.3.15-10.10.3.1610.10.3.0
199.10.3.0-199.10.3.9, 199.10.3.11, 199.10.3.15-199.10.3.1610.10.3.9
10.10.3.11
10.10.3.15
10.10.3.16
199.10.3.0
199.10.3.9
199.10.3.11
199.10.3.15
199.10.3.16
 
Last edited:
Upvote 0
Sandy, I came up with the same solution and then realized that the "-" indicated the OP was looking to add in the range of missing IPs. I could not figure out how to fill that range using PQ. Your thoughts on this.
 
Upvote 0
You'll need use last number from IPs which contain "-" then use something like this: try {[IfTAD1]..[TAD2]} otherwise null where IFTAD1 is the last number from first IP and TAD2 is a last number from the second IP (after "-") - it will give you a list of last numbers: eg. 0 1 2 3 4 5 6 7 8 9 then you can replace lat number of the first IPs with these number from the list
somehow you need eliminate IPs without "-"
I know , this is a bit twisted :biggrin:

10.10.3.0-10.10.3.9
 
Upvote 0
but I don't know if this should be treated the same way
ips.png

like 11 12 13 14 15
 
Upvote 0
like this?
without situation mentioned in post#7
rawIPs
10.10.3.0-10.10.3.9, 10.10.3.11, 10.10.3.15-10.10.3.1610.10.3.0
199.10.3.0-199.10.3.9, 199.10.3.11, 199.10.3.15-199.10.3.1610.10.3.1
10.10.3.2
10.10.3.3
10.10.3.4
10.10.3.5
10.10.3.6
10.10.3.7
10.10.3.8
10.10.3.9
10.10.3.11
10.10.3.15
199.10.3.0
199.10.3.1
199.10.3.2
199.10.3.3
199.10.3.4
199.10.3.5
199.10.3.6
199.10.3.7
199.10.3.8
199.10.3.9
199.10.3.11
199.10.3.15
 
Upvote 0

Forum statistics

Threads
1,215,681
Messages
6,126,194
Members
449,298
Latest member
Jest

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top