Avatar of Mike
Mike
Flag for United States of America asked on

Need Help with Transposing Data in Excel

Greeting Experts,

I have a list of Servers with a List of local user accounts for each one... Each Row has multiple user names in each row. (example below). What I need to do is Transpose the data with the Device Name & IP address with the local admin user account next to each one (example below). can somebody advise the best way to do this...

current Layout 
 
Host NameHost IPUserName1UserName2UserName3
PCName1192.168.0.1AdministratorDefault1AdministratorDefault2AdministratorDefault3
PCname2192.168.0.2AdministratorDefaultkrbtgtguest
PCName3192.168.0.3AdministratorDefaultkrbtgtguest
PCName4192.168.0.4AdministratorDefaultkrbtgtguest
PeName5192.168.0.5AdministratorDefaultkrbtgtguest

What I looking to Do

Host NameHost IPUserName
PCName1192.168.0.1AdministratorDefault1
PCName1192.168.0.1AdministratorDefault2
PCName1192.168.0.1AdministratorDefault3
PCName1192.168.0.1AdministratorDefault4
PCname2192.168.0.2AdministratorDefault
PCname2192.168.0.2krbtgt
PCname2192.168.0.2guest
PCName3192.168.0.3AdministratorDefault
PCName3192.168.0.3krbtgt
PCName3192.168.0.3guest
PCName4192.168.0.4AdministratorDefault
PCName4192.168.0.4krbtgt
PCName4192.168.0.4guest
PCName5192.168.0.5AdministratorDefault
PCName5192.168.0.5krbtgt
PCName5192.168.0.5guest

* powerhsell* Excel TableSpreadsheets

Avatar of undefined
Last Comment
Mike

8/22/2022 - Mon
Robert Berke

You can accomplish this easily with vba.

Option Explicit

Sub UNPIVOT()
Dim ARY()
Dim shtNew As Worksheet, r As Long, c As Long, newR As Long, newC As Long
With Selection
    Set shtNew = Worksheets.Add
    On Error Resume Next
    Application.DisplayAlerts = False
    Sheets("Unpivot").Delete
    Application.DisplayAlerts = True
    On Error GoTo 0
    shtNew.Name = "UnPivot"

    
    For r = 1 To .Rows.Count
        newC = 0
        For c = 3 To .Columns.Count
            If r = 1 Then
                newR = 1
            Else
                newR = newR + 1
            End If
            
            shtNew.Cells(newR, 1) = .Cells(r, 1)
            shtNew.Cells(newR, 2) = .Cells(r, 2)
            shtNew.Cells(newR, 3) = .Cells(r, c)
'            MsgBox shtnew.Cells(NEWR, 1) & " " & ARY(NEWR, 2) & " " & ARY(NEWR, 3)
        Next c
        
        
        Next r
    MsgBox "done"
     Sub

Open in new window


If there were 5 user name columns and you wanted to do this without vba
1. copy whole area.
2. create a new sheet named UnPivot
3. paste the area 5 times into UnPivot
4. In the second pasted area select the cells in C and delete them with shift right.
5. In the thired pasted area select the cell in C:d and delete them
6. In the fourth area delete c:e
7. in the fifth area delete c:f
8. to finish things off, delete cells d:f


ASKER CERTIFIED SOLUTION
Robert Berke

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Mike

ASKER
Thanks 
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23