Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Split data in GML file into Excel file

Posted on 2012-04-05
16
Medium Priority
?
1,744 Views
Last Modified: 2012-04-06
Hello,

I have a GML file, please find it attached.  I was wondering if there is an automated way in Excel to parse the data in the file.  So all I need from the GML file is the Source and Destination data.  I would like to create two columns in an Excel, one that says Source and once that says Destination.  I would like to insert the source and destination data from the GML file into those respective columns in the Excel file.  But I have to be sure that they match what is the GML file.

Does anybody know of an automated way to do this, as I am sure there is one.

Thank You.
0
Comment
Question by:navid86
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
16 Comments
 
LVL 46

Expert Comment

by:aikimark
ID: 37815703
please post a sample copy of the GML file.
0
 
LVL 2

Author Comment

by:navid86
ID: 37815914
I apologize, forgot to post it.  I am posting it in Excel file format, because EE won't accept .GML attachment.  All I did was just copy and paste from GML file into column a of Excel.
book1.xlsx
0
 
LVL 46

Expert Comment

by:aikimark
ID: 37815957
@navid86

Does this version of the file look like what you see?
Q-27664592.txt
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:navid86
ID: 37815992
Yes, thats exactly what I see in the GML file.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 37816150
Do you mean the values that follow the source and target strings?
0
 
LVL 2

Author Comment

by:navid86
ID: 37816190
yeah so I would like one column to say source and the other target.  Then add the corresponding values to the column.  So an example from the GML file is this:

    source 1435
    target 1278

I would like it to be in two columns in excel like this.

Source          Target
1435             1278

Just have to make sure that those values match up with what is in the txt file, like make sure 1435's target is 1278.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 37816215
something like this?
Q-27664592.xls
0
 
LVL 46

Accepted Solution

by:
aikimark earned 2000 total points
ID: 37816232
closer?
Q-27664592.xls
0
 
LVL 2

Author Comment

by:navid86
ID: 37816241
Yes, except is there anyway to make the column headings source and target and remove source and target from the rows and just leave the numbers?
0
 
LVL 46

Expert Comment

by:aikimark
ID: 37816257
I thought that's what I posted
0
 
LVL 2

Author Comment

by:navid86
ID: 37816266
Sorry, didnt see your second post.  Thank you very much for your help!  Just so I know for future reference how did you do this?
0
 
LVL 46

Assisted Solution

by:aikimark
aikimark earned 2000 total points
ID: 37816337
I did this manually
* import as fixed text, starting with the "source" string column, not importing the first column.
* fill right two columns
* add a new worksheet
* copy the second column into the new worksheet
* Select the usedrange cells and apply an autofilter
* do a custom filter (does not begin with s)
* Delete the rows
* copy the column back to the original worksheet
* repeat for the third column, with a different custom filter (does not begin with t)
In the original worksheet
* select the second column
* Edit replace all "source " with nothing
* select the third column
* Edit replace all "target " with nothing
* change the column headers for the second and third columns to source and target
* delete the first column
* Save As Excel format

===================
If you need to do this on multiple occasions, you could record a macro with these steps or you could create some VBA code to do this programmatically with a different process.
0
 
LVL 2

Author Comment

by:navid86
ID: 37816345
great thank you!
0
 
LVL 46

Expert Comment

by:aikimark
ID: 37816379
Here is an example of a code-centric solution.

Option Explicit

Public Sub ParseSourceTarget()
    Dim wks As Worksheet
    Dim rng As Range
    Dim rngCell As Range
    Dim rngTgt As Range
    
    Set wks = ActiveSheet
    Set rng = wks.UsedRange
    Set rngTgt = wks.Range("B2")
    
    Application.ScreenUpdating = False
    
    For Each rngCell In rng
        Select Case True
            Case rngCell.Value Like "*source #*"
                rngTgt.Value = Split(rngCell.Value, "source ")(1)
            Case rngCell.Value Like "*target #*"
                rngTgt.Offset(0, 1).Value = Split(rngCell.Value, "target ")(1)
                Set rngTgt = rngTgt.Offset(1)
        End Select
    Next
    
    wks.Range("B1").Value = "source"
    wks.Range("C1").Value = "target"
    wks.Range("A:A").EntireColumn.Delete
    
    Application.ScreenUpdating = True
End Sub

Open in new window

0
 
LVL 46

Expert Comment

by:aikimark
ID: 37816387
in the code-centric solution, I read the file as fixed text with a single column, starting with the first column.
0
 
LVL 2

Author Comment

by:navid86
ID: 37816396
Cool, thanks for taking the time to post the VBA code.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
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…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

597 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