Loop through all the data and display them in proper format.

faizal Izham

New Member
Joined
Oct 26, 2017
Messages
7
I would like to seek help from the expert in Mr.Excel with my issue below.

i have some sample data as per below. Host is in 1 table and Port is on another table.
HostPort1Port2Port3
Host11A1B1C
Host2

<tbody>
</tbody>

I would like to output the data as per below in another sheet.
HostOutput
Host1Host1_1A
Host1Host1_1B
Host1Host1_1C
Host2Host2_1A
Host2Host2_1B
Host2Host2_1C

<tbody>
</tbody>

Below is other sample on the data.

<tbody>
</tbody>

HostPort1Port2Port3
Host11A1B
Host2
Host3

<tbody>
</tbody>

If the Column in Port is empty it will skipped to the next host and loop with the available port.
HostOutput
Host1Host1_1A
Host1Host1_1B
Host2Host2_1A
Host2Host2_1B
Host3Host3_1A
Host3Host3_1B

<tbody>
</tbody>

Hope someone can help me with the formula to automatically loop around the data.

Thank You in advance for helping.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
in the top table, there is nothing against Host2, so why does it have 1A 1B 1C next to it in the second table ?
 
Upvote 0
Hi Oldbrewer,

actually the Host table and port table two seperate table. Each host will have to refer to port table to determine how many port the host have.
hope that helps.

Thanks in advance.
 
Upvote 0
it is not clear to me which tables are "information" tables and which table is your desired output. You refer to port table - which is it - and how does host 3 get 1a and 1b next to it ?
 
Upvote 0
Give this macro a try (change the output sheet name as required)...
Code:
[table="width: 500"]
[tr]
	[td]Sub HostPortTable()
  Dim R As Long, C As Long, X As Long
  Dim Hosts As Variant, Ports As Variant, HostPort As Variant
  Hosts = Range("A2", Cells(Rows.Count, "A").End(xlUp)).Value
  Ports = Range("C2", Range("C2").End(xlToRight)).Value
  ReDim HostPort(1 To UBound(Hosts, 1) * UBound(Ports, 2), 1 To 2)
  For R = 1 To UBound(Hosts, 1)
    For C = 1 To UBound(Ports, 2)
      X = X + 1
      HostPort(X, 1) = Hosts(R, 1)
      HostPort(X, 2) = Hosts(R, 1) & "_" & Ports(1, C)
    Next
  Next
  Sheets("[B][COLOR="#FF0000"]Sheet2[/COLOR][/B]").Range("A1").Resize(UBound(HostPort), 2) = HostPort
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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