Very hard to transform table (Maybe with transpose formula ?)

mexiro

New Member
Joined
Nov 30, 2012
Messages
5
Hello Guys,

I have an excel output which pings some IP for several PC each hour. PCs at a given time are either online or offline. I need to gather data and prepare lists of PCs going offline, and later even make a chart of it. Most of the time PCs are online so what it matters is offline (disconnections)

data is as below:

[TABLE="width: 248"]
<tbody>[TR]
[TD] Time[/TD]
[TD]PC NAME[/TD]
[TD]Status:[/TD]
[/TR]
[TR]
[TD="align: right"]06:27:44[/TD]
[TD]PC1[/TD]
[TD]Online[/TD]
[/TR]
[TR]
[TD="align: right"]06:27:44[/TD]
[TD]PC2[/TD]
[TD]Online[/TD]
[/TR]
[TR]
[TD="align: right"]06:27:44[/TD]
[TD]PC3[/TD]
[TD]Online[/TD]
[/TR]
[TR]
[TD="align: right"]06:27:44[/TD]
[TD]PC4[/TD]
[TD]Online[/TD]
[/TR]
[TR]
[TD="align: right"]06:27:44[/TD]
[TD]PC5[/TD]
[TD]Offline[/TD]
[/TR]
[TR]
[TD="align: right"]07:27:44[/TD]
[TD]PC1[/TD]
[TD]Offline[/TD]
[/TR]
[TR]
[TD="align: right"]07:27:44[/TD]
[TD]PC2[/TD]
[TD]Online[/TD]
[/TR]
[TR]
[TD="align: right"]07:27:44[/TD]
[TD]PC3[/TD]
[TD]Online[/TD]
[/TR]
[TR]
[TD="align: right"]07:27:44[/TD]
[TD]PC4[/TD]
[TD]Online[/TD]
[/TR]
[TR]
[TD="align: right"]07:27:44[/TD]
[TD]PC5[/TD]
[TD]Online[/TD]
[/TR]
[TR]
[TD="align: right"]08:27:44[/TD]
[TD]PC1[/TD]
[TD]Offline[/TD]
[/TR]
[TR]
[TD="align: right"]08:27:44[/TD]
[TD]PC2[/TD]
[TD]Online[/TD]
[/TR]
[TR]
[TD="align: right"]08:27:44[/TD]
[TD]PC3[/TD]
[TD]Offline[/TD]
[/TR]
[TR]
[TD="align: right"]08:27:44[/TD]
[TD]PC4[/TD]
[TD]Online[/TD]
[/TR]
[TR]
[TD="align: right"]08:27:44[/TD]
[TD]PC5[/TD]
[TD]Online[/TD]
[/TR]
[TR]
[TD="align: right"]09:27:44[/TD]
[TD]PC1[/TD]
[TD]Online[/TD]
[/TR]
[TR]
[TD="align: right"]09:27:44[/TD]
[TD]PC2[/TD]
[TD]Online[/TD]
[/TR]
[TR]
[TD="align: right"]09:27:44[/TD]
[TD]PC3[/TD]
[TD]Offline[/TD]
[/TR]
[TR]
[TD="align: right"]09:27:44[/TD]
[TD]PC4[/TD]
[TD]Online[/TD]
[/TR]
[TR]
[TD="align: right"]09:27:44[/TD]
[TD]PC5[/TD]
[TD]Online[/TD]
[/TR]
</tbody>[/TABLE]


I need to gather data from the above to the below table:
[TABLE="width: 349"]
<tbody>[TR]
[TD]PC NAME[/TD]
[TD]Status:[/TD]
[TD]Time Offline[/TD]
[TD]Time back to online[/TD]
[/TR]
[TR]
[TD]PC5[/TD]
[TD]Offline[/TD]
[TD="align: right"]06:27:44 PM[/TD]
[TD="align: right"]07:27:44 PM[/TD]
[/TR]
[TR]
[TD]PC1[/TD]
[TD]Offline[/TD]
[TD="align: right"]07:27:44 PM[/TD]
[TD="align: right"]08:27:44 PM[/TD]
[/TR]
[TR]
[TD]PC3[/TD]
[TD]Offline[/TD]
[TD="align: right"]08:27:44 PM[/TD]
[TD]N/A#[/TD]
[/TR]
</tbody>[/TABLE]

According to the above I need to make a report on a PC how often disconnected and for how long. I also need to make a chart of it, but for the moment I need to gather the data in this way.

Any help?

thanks,
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Assuming the data point for PC1 at 8:27:44 should be "Online" rather than the "Offline" your post shows, this seems to work.
The data are transformed in cols F:I as shown below:
Excel Workbook
ABCDEFGHI
1TimePC NAMEStatus:PC NAMEStatusTime OfflineTime back to online
26:27:44PC1OnlinePC5Offline6:27:44 AM7:27:44 AM
36:27:44PC2OnlinePC1Offline7:27:44 AM8:27:44 AM
46:27:44PC3OnlinePC3Offline8:27:44 AM
56:27:44PC4Online
66:27:44PC5Offline
77:27:44PC1Offline
87:27:44PC2Online
97:27:44PC3Online
107:27:44PC4Online
117:27:44PC5Online
128:27:44PC1Online
138:27:44PC2Online
148:27:44PC3Offline
158:27:44PC4Online
168:27:44PC5Online
179:27:44PC1Online
189:27:44PC2Online
199:27:44PC3Offline
209:27:44PC4Online
219:27:44PC5Online
Sheet1


Code:
Sub mexiro()
Dim lR As Long, R As Range, vA As Variant, vB As Variant, vO() As Variant, nR _
    As Long, i As Long, j As Long, ct As Long
lR = Range("B" & Rows.Count).End(xlUp).Row
Set R = Range("A1:C" & lR)
vA = R.Value
Application.ScreenUpdating = False
Columns("F:I").ClearContents
With Range("F1:I1")
    .Value = Array("PC NAME", "Status", "Time Offline", "Time back to online")
    .Font.Bold = True
    .WrapText = True
End With
ReDim vO(1 To UBound(vA, 1), 1 To 4)
For i = LBound(vA, 1) To UBound(vA, 1)
    If vA(i, 3) = "Offline" Then
        If i < lR Then
            ct = ct + 1
            vO(ct, 1) = vA(i, 2)
            vO(ct, 2) = vA(i, 3)
            vO(ct, 3) = vA(i, 1)
            For j = i + 1 To UBound(vA, 1)
                If vA(j, 2) = vA(i, 2) And vA(j, 3) = "Online" Then
                    vO(ct, 4) = vA(j, 1)
                    Exit For
                End If
            Next j
        Else
            ct = ct + 1
            vO(ct, 1) = vA(i, 2)
            vO(ct, 2) = vA(i, 3)
            vO(ct, 3) = vA(i, 1)
            vO(ct, 4) = CVErr(xlErrNA)
            
        End If
    End If
Next i
nR = Range("F" & Rows.Count).End(xlUp).Row + 1
Range("F2:I" & ct).Value = vO
Columns("H:I").NumberFormat = "[$-F400]h:mm:ss AM/PM"
Columns("F:I").AutoFit
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,287
Messages
6,190,059
Members
453,592
Latest member
bcexcel

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