Combine data in 2 cels

gyagos

New Member
Joined
Mar 27, 2018
Messages
27
Office Version
  1. 365
Platform
  1. Windows
All,
I have been searching and i cannot find the answer. I have many rows on a spreadsheet that have multiple IPs associated. What i need to do is breakout all IPs but still retain the hostname and add the IP after the hostname. These are just a few examples, there are many instances of 5+ IPs on a host

Current Data
HostnameIps
"Server-1-a01-name""111.22.3333.444","111.22.333.555"
"Server-2-a02-name""123.45.678.900","123.45.678.901","123.45.678.902"


What i would like the layout to look like

Hostname
"Server-1-a01-name" - "111.22.333.444"
"Server-1-a01-name" - "111.22.333.555"
"Server-2-a02-name" - "123.45.678.900"
"Server-2-a02-name" - "123.45.678.901"
"Server-2-a02-name" - "123.45.678.902"
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Do you want the quotes?
how about:

It isn't all in one column though.
mr excel questions 25.xlsm
ABCDE
1HostnameIps
2"Server-1-a01-name""111.22.3333.444","111.22.333.555""Server-1-a01-name"-"111.22.3333.444""Server-1-a01-name"-"111.22.333.555"
3"Server-2-a02-name""123.45.678.900","123.45.678.901","123.45.678.902""Server-2-a02-name"-"123.45.678.900""Server-2-a02-name"-"123.45.678.901""Server-2-a02-name"-"123.45.678.902"
4
gyagos
Cell Formulas
RangeFormula
C2:D2,C3:E3C2=SUBSTITUTE(TEXTSPLIT(REPLACE(REPT(","& A2,COUNTA(TEXTSPLIT(B2,","))),1,1,""),",")& TEXTSPLIT(B2,","),CHAR(34)&CHAR(34),CHAR(34)&"-"&CHAR(34))
Dynamic array formulas.
 
Upvote 0
Thanks
I would prefer if they were all in same column, but i could probably cut and transpose if needed
I'll try this out later on tonite
 
Upvote 0
You could try like this. If your list is very large, the formula could fail since TEXTJOIN has a character limit of 32,767 characters.
23 04 22.xlsm
ABCDE
1HostnameIps
2"Server-1-a01-name""111.22.3333.444","111.22.333.555""Server-1-a01-name""111.22.3333.444"
3"Server-2-a02-name""123.45.678.900","123.45.678.901","123.45.678.902""Server-1-a01-name""111.22.333.555"
4"Server-2-a02-name""123.45.678.900"
5"Server-2-a02-name""123.45.678.901"
6"Server-2-a02-name""123.45.678.902"
Split List
Cell Formulas
RangeFormula
D2:E6D2=TEXTSPLIT(TEXTJOIN("|",,BYROW(A2:B3,LAMBDA(rw,INDEX(rw,1)&","&SUBSTITUTE(INDEX(rw,2),",","|"&INDEX(rw,1)&",")))),",","|")
Dynamic array formulas.
 
Upvote 0
If your list is very large, the formula could fail since TEXTJOIN has a character limit of 32,767 characters.
If that is a possible problem then you could try this macro instead.

VBA Code:
Sub Split_IP_List()
  Dim a As Variant, b As Variant, IPs As Variant
  Dim i As Long, j As Long, k As Long
  
  a = Range("A2", Range("B" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To Rows.Count, 1 To 2)
  For i = 1 To UBound(a)
    IPs = Split(a(i, 2), ",")
    For j = 0 To UBound(IPs)
      k = k + 1
      b(k, 1) = a(i, 1): b(k, 2) = IPs(j)
    Next j
  Next i
  Range("D2:E2").Resize(k).Value = b
End Sub
 
Upvote 0
:oops: Oops, I missed that results should be in a single column so revised suggestions for both methods.

gyagos.xlsm
ABCD
1HostnameIps
2"Server-1-a01-name""111.22.3333.444","111.22.333.555""Server-1-a01-name" - "111.22.3333.444"
3"Server-2-a02-name""123.45.678.900","123.45.678.901","123.45.678.902""Server-1-a01-name" - "111.22.333.555"
4"Server-2-a02-name" - "123.45.678.900"
5"Server-2-a02-name" - "123.45.678.901"
6"Server-2-a02-name" - "123.45.678.902"
Split List
Cell Formulas
RangeFormula
D2:D6D2=TEXTSPLIT(TEXTJOIN("|",,BYROW(A2:B3,LAMBDA(rw,INDEX(rw,1)&" - "&SUBSTITUTE(INDEX(rw,2),",","|"&INDEX(rw,1)&" - ")))),,"|")
Dynamic array formulas.


VBA Code:
Sub Split_IP_List_v2()
  Dim a As Variant, b As Variant, IPs As Variant
  Dim i As Long, j As Long, k As Long
 
  a = Range("A2", Range("B" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To Rows.Count, 1 To 1)
  For i = 1 To UBound(a)
    IPs = Split(a(i, 2), ",")
    For j = 0 To UBound(IPs)
      k = k + 1
      b(k, 1) = a(i, 1) & " - " & IPs(j)
    Next j
  Next i
  Range("D2").Resize(k).Value = b
End Sub
 
Upvote 0
Solution
Thank you Peter and awoohaw.
i tried the =TEXTSPLIT and it came back with a #CALC error (Text too long)
The Macro worked like a charm.
 
Upvote 0
You're welcome. Glad the macro worked for you. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,215,201
Messages
6,123,621
Members
449,109
Latest member
Sebas8956

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