[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Large Data Pool Import & Transpose

Posted on 2010-04-07
14
Medium Priority
?
369 Views
Last Modified: 2012-08-13
Hey all, simple question I'd assume..

I have a notepad file, currently saved as a .log file. I need to import it into Excel. Easy enough, with the import external data feature. My issue arises due to the fact I need to transpose this data, which is easy to do, but I have 255 entries I need transpose. Is there an option / way to specify the transpose when importing the data in excel?

Currently, the data looks like this;

Host Name:         No DNS Entry
IP Address:        192.168.1.1
Ping Response:     ip dest host unreachable
Ethernet Address:  
Network Interface:
Host Type:        
Open Ports:        
FTP Server:        
WINS Name:        
Windows Workgroup:
Current User:      
WINS Comment:

I need the entire field of 255 IP's transposed across. I can create the horizontal Host Name, IP Address, etc title blocks, but how do I go about transposing the actual data I've gotten off my network scan, without doing it 255 times?

Thanks
0
Comment
Question by:microsymplex
  • 8
  • 6
14 Comments
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 30064689
It would be helpful if you could upload a sample of your log file, and a mockup of how the results should look in Excel.

Be sure to first obfuscate any sensitive data in the log :)
0
 

Author Comment

by:microsymplex
ID: 30118795
Attached are my examples. the notepad example is how I get the raw data from my scanning software, netpeek. the green excel cells are how they are getting imported now, the cells in orange are how I want them to be imported, horizontally instead of vertically. Remember I have my entire subnet to do, all 255 addresses, so a simple copy and transpose is not necessarily feasible.

Thanks!
example.txt
example2.xlsx
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 30131828
Please download the file below, and run the macro GetTheData.

It reads the data from the text file, and writes the results to a new workbook.
Sub GetTheData()
    
    Dim fso As Object
    Dim ts As Object
    Dim ws As Worksheet
    Dim FilePath As Variant
    Dim UseRow As Long
    Dim TheLine As String
    Dim Header As String
    Dim Item As String
    Dim UseCol As Long
    
    FilePath = Application.GetOpenFilename("Text (*.txt), *.txt", , "Select log file", , False)
    If FilePath = False Then
        MsgBox "No file selected", vbCritical, "Aborting..."
        Exit Sub
    End If
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.OpenTextFile(FilePath)
    ThisWorkbook.Worksheets(1).Copy
    Set ws = ActiveSheet
    
    UseRow = 1
    
    Do Until ts.AtEndOfStream
        TheLine = ts.ReadLine
        If InStr(1, TheLine, ":") > 0 Then
            Header = Split(TheLine, ":")(0)
            Item = Trim(Split(TheLine, ":")(1))
            If StrComp(Header, "Host Name", vbTextCompare) = 0 Then UseRow = UseRow + 1
            UseCol = Application.Match(Header, ws.[1:1], 0)
            ws.Cells(UseRow, UseCol) = Item
        End If
    Loop
    
    ts.Close
    Set ts = Nothing
    Set fso = Nothing
    
    ws.Columns.AutoFit
    
    MsgBox "Done"
    
End Sub

Open in new window

Q-25755763.xls
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:microsymplex
ID: 30140444
Thanks, but when I go to open the text file with all the data (not the example I uploaded) Excel does not list it as an option in the folder where I have it stored.
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 30141018
Change:

    FilePath = Application.GetOpenFilename("Text (*.txt), *.txt", , "Select log file", , False)

to:

    FilePath = Application.GetOpenFilename("Log (*.log), *.log", , "Select log file", , False)
0
 

Author Comment

by:microsymplex
ID: 30141108
Disregard the other error, but when I open it, I get a run time error '13': Type Mismatch.
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 30145764
When I run the macro against the sample file you provided, it works perfectly.

Which line did the debugger jump to, and can you post the exact file you tried to run against?
0
 

Author Comment

by:microsymplex
ID: 30145957
I can't post the exact file, since it has mac addresses, ports, names, ip's, etc. But the format is exactly the same as the example I posted, only it's all 255 IP address, not the 5 or 6 that were included in my example. I apologize for not making that more clear...Yes the macro works with the example, but not the full file I need to run it on in my production environment.

Thanks!
0
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 2000 total points
ID: 30146310
Try this...



Sub GetTheData()
    
    Dim fso As Object
    Dim ts As Object
    Dim ws As Worksheet
    Dim FilePath As Variant
    Dim UseRow As Long
    Dim TheLine As String
    Dim Header As String
    Dim Item As String
    Dim UseCol As Long
    
    FilePath = Application.GetOpenFilename("Log (*.log), *.log", , "Select log file", , False)
    If FilePath = False Then
        MsgBox "No file selected", vbCritical, "Aborting..."
        Exit Sub
    End If
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.OpenTextFile(FilePath)
    Set ws = Workbooks.Add.Worksheets(1)
    
    UseRow = 1
    
    Do Until ts.AtEndOfStream
        TheLine = ts.ReadLine
        If InStr(1, TheLine, ":") > 0 Then
            Header = Split(TheLine, ":")(0)
            Item = Trim(Split(TheLine, ":")(1))
            If StrComp(Header, "Host Name", vbTextCompare) = 0 Then
                UseRow = UseRow + 1
            End If
            If Application.CountIf(ws.[1:1], Header) = 0 Then
                ws.Cells(1, Application.CountA(ws.[1:1]) + 1) = Header
            End If
            UseCol = Application.Match(Header, ws.[1:1], 0)
            ws.Cells(UseRow, UseCol) = Item
        End If
    Loop
    
    ts.Close
    Set ts = Nothing
    Set fso = Nothing
    
    ws.Columns.AutoFit
    
    MsgBox "Done"
    
End Sub

Open in new window

0
 

Author Comment

by:microsymplex
ID: 30150574
will test in the morning, thanks!
0
 

Author Comment

by:microsymplex
ID: 30213088
Ok I'm really sorry but I know nothing except total basics of macros, what do I do with the text you attached?
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 30214443
Hit Alt+F11 to get the VB Editor, and replace the original code I gave you with the updated code in http:#a30146310
0
 

Author Comment

by:microsymplex
ID: 30214697
gotcha.
0
 

Author Closing Comment

by:microsymplex
ID: 31712071
Perfect, exactly what I needed. Thank you for the continued follow up and assistance!
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

: Microsoft Office Collaborate for free and online versions of Microsoft  Word, Excel, Powerpoint, OneNote, Onedrive , Email, Calendar etc. In short we can say that Microsoft office is a suite of servers, applications and services developed by  Micr…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

613 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question