+ Reply to Thread
Results 1 to 9 of 9

Matrix to a Column Report

  1. #1
    Dave
    Guest

    Matrix to a Column Report

    Hello - I have a csv file in the form of a matrix with >256 variables (e.g.
    300 x 300) that I want to summarize to a column report. For example:

    Var1 Var2 Var3
    Var1 1 2 3
    Var2 4 5 6
    Var3 7 8 9


    And I would like the output to be:
    Var1, Var1 1
    Var1, Var2 2
    Var1, Var3 3
    Var2, Var1 4
    Var2, Var2 5
    Var2, Var3 6
    Var3, Var1 7
    Var3, Var2 8
    Var3, Var3 9

    Anyone know of an easy way to do this in VBA?

  2. #2
    Ardus Petus
    Guest

    Re: Matrix to a Column Report

    Your example is not clear.
    Could you specify Var1, Var2 & var 3's values

    HTH
    --
    AP

    "Dave" <[email protected]> a écrit dans le message de news:
    [email protected]...
    > Hello - I have a csv file in the form of a matrix with >256 variables
    > (e.g.
    > 300 x 300) that I want to summarize to a column report. For example:
    >
    > Var1 Var2 Var3
    > Var1 1 2 3
    > Var2 4 5 6
    > Var3 7 8 9
    >
    >
    > And I would like the output to be:
    > Var1, Var1 1
    > Var1, Var2 2
    > Var1, Var3 3
    > Var2, Var1 4
    > Var2, Var2 5
    > Var2, Var3 6
    > Var3, Var1 7
    > Var3, Var2 8
    > Var3, Var3 9
    >
    > Anyone know of an easy way to do this in VBA?




  3. #3
    Tom Ogilvy
    Guest

    RE: Matrix to a Column Report

    if it is 300 x 300, you would need to write out 90,000 rows, but there are
    only 65,536

    is the first row and first column actually variable names.

    A CSV file usually means comma separated, but you show fixed width. What
    does your file actually look like?

    do you really need the result in excel or just write it back out to another
    CSV file?


    In your sample output,
    Var1, var2, 2

    is the Var1 from the left side of the input (row) or from the top row
    (column)?


    You show
    row var, column var, value

    (based on the value 2), but just to be sure.

    --
    Regards,
    Tom Ogilvy


    "Dave" wrote:

    > Hello - I have a csv file in the form of a matrix with >256 variables (e.g.
    > 300 x 300) that I want to summarize to a column report. For example:
    >
    > Var1 Var2 Var3
    > Var1 1 2 3
    > Var2 4 5 6
    > Var3 7 8 9
    >
    >
    > And I would like the output to be:
    > Var1, Var1 1
    > Var1, Var2 2
    > Var1, Var3 3
    > Var2, Var1 4
    > Var2, Var2 5
    > Var2, Var3 6
    > Var3, Var1 7
    > Var3, Var2 8
    > Var3, Var3 9
    >
    > Anyone know of an easy way to do this in VBA?


  4. #4
    Dave
    Guest

    Re: Matrix to a Column Report

    This is actually correlation report, where each value within this matrix is
    the correlation between the 2 variables. Here is a more specific example:

    Var1 Var2 Var3
    Var1 1 .9 .1
    Var2 .9 1 .8
    Var3 .1 .8 1

    So, for example, the correlation betwen Var1 and Var2 is .9

    And this is contained within a .csv file so the file will look like this:

    ,Var1,Var2,Var3
    Var1,1,.9,.1
    Var2,.9,1,.8
    Var3,.1,.8,1

    And I need an output that looks like this:

    Var1,Var1,1
    Var1,Var2,.9
    Var1,Var3,.1
    Var2,Var1,.9
    Var2,Var2,1
    Var2,Var3,.8
    Var3,Var1,.1
    Var3,Var2,.8
    Var3,Var3,1

    Does that help?


    "Ardus Petus" wrote:

    > Your example is not clear.
    > Could you specify Var1, Var2 & var 3's values
    >
    > HTH
    > --
    > AP
    >
    > "Dave" <[email protected]> a écrit dans le message de news:
    > [email protected]...
    > > Hello - I have a csv file in the form of a matrix with >256 variables
    > > (e.g.
    > > 300 x 300) that I want to summarize to a column report. For example:
    > >
    > > Var1 Var2 Var3
    > > Var1 1 2 3
    > > Var2 4 5 6
    > > Var3 7 8 9
    > >
    > >
    > > And I would like the output to be:
    > > Var1, Var1 1
    > > Var1, Var2 2
    > > Var1, Var3 3
    > > Var2, Var1 4
    > > Var2, Var2 5
    > > Var2, Var3 6
    > > Var3, Var1 7
    > > Var3, Var2 8
    > > Var3, Var3 9
    > >
    > > Anyone know of an easy way to do this in VBA?

    >
    >
    >


  5. #5
    Dave
    Guest

    RE: Matrix to a Column Report

    Hi Tom - Here are some answers to your questions:

    "Tom Ogilvy" wrote:

    > if it is 300 x 300, you would need to write out 90,000 rows, but there are
    > only 65,536

    Ya, I will then bring this new file into Access. I would bring the original
    file into Access but it has the 256 variable limitation as well.

    > is the first row and first column actually variable names.

    Yes

    > A CSV file usually means comma separated, but you show fixed width. What
    > does your file actually look like?

    Sorry, I should have been more specific. I just posted an answer to Ardus'
    question that shows an example of what my file actually looks like.

    > do you really need the result in excel or just write it back out to another
    > CSV file?

    Output to a .csv file would be great.

    >
    >
    > In your sample output,
    > Var1, var2, 2
    >
    > is the Var1 from the left side of the input (row) or from the top row
    > (column)?
    >
    >
    > You show
    > row var, column var, value
    >
    > (based on the value 2), but just to be sure.

    Thanks for clarifying, yes this is correct.

    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Dave" wrote:
    >
    > > Hello - I have a csv file in the form of a matrix with >256 variables (e.g.
    > > 300 x 300) that I want to summarize to a column report. For example:
    > >
    > > Var1 Var2 Var3
    > > Var1 1 2 3
    > > Var2 4 5 6
    > > Var3 7 8 9
    > >
    > >
    > > And I would like the output to be:
    > > Var1, Var1 1
    > > Var1, Var2 2
    > > Var1, Var3 3
    > > Var2, Var1 4
    > > Var2, Var2 5
    > > Var2, Var3 6
    > > Var3, Var1 7
    > > Var3, Var2 8
    > > Var3, Var3 9
    > >
    > > Anyone know of an easy way to do this in VBA?


  6. #6
    Tom Ogilvy
    Guest

    RE: Matrix to a Column Report

    Sub convertData()
    Dim ans As Long, hdr As Variant
    Dim fName As Variant, s As String
    Dim i As Long, j As Long
    Dim ff As Long, ff1 As Long
    Dim l1 As String, l As String
    Dim v As Variant
    Dim fName1 As String, sPath As String
    ChDrive "C"
    ChDir "C:\Chris"
    fName = Application.GetOpenFilename("CSV Files (*.CSV),*.CSV")
    If fName = False Then
    Exit Sub
    End If
    fName1 = Replace(LCase(fName), ".csv", "_CONVERTED.csv")

    s = fName & vbNewLine & vbNewLine & _
    "will be converted and results stored in " & _
    vbNewLine & vbNewLine & fName1 & vbNewLine & _
    vbNewLine & "Proceed?"
    ans = MsgBox(Prompt:=s, _
    Buttons:=vbYesNo + vbQuestion, _
    Title:="Convert " & fName1)
    If ans = vbNo Then
    MsgBox "You chose to quit. Ending", vbCritical
    Exit Sub
    End If
    ff = FreeFile()
    Open fName For Input As ff
    ff1 = FreeFile()
    Open fName1 For Output As ff1
    Line Input #ff, l1
    hdr = Split(l1, ",")
    Do While Not EOF(ff)
    Line Input #ff, l
    v = Split(l, ",")
    For j = LBound(hdr) + 1 To UBound(hdr)
    Print #ff1, v(LBound(v)) & "," & hdr(j) & "," & v(j)
    Next j
    Loop
    Close #ff
    Close #ff1
    End Sub


    --
    Regards,
    Tom Ogilvy


    "Dave" wrote:

    > Hi Tom - Here are some answers to your questions:
    >
    > "Tom Ogilvy" wrote:
    >
    > > if it is 300 x 300, you would need to write out 90,000 rows, but there are
    > > only 65,536

    > Ya, I will then bring this new file into Access. I would bring the original
    > file into Access but it has the 256 variable limitation as well.
    >
    > > is the first row and first column actually variable names.

    > Yes
    >
    > > A CSV file usually means comma separated, but you show fixed width. What
    > > does your file actually look like?

    > Sorry, I should have been more specific. I just posted an answer to Ardus'
    > question that shows an example of what my file actually looks like.
    >
    > > do you really need the result in excel or just write it back out to another
    > > CSV file?

    > Output to a .csv file would be great.
    >
    > >
    > >
    > > In your sample output,
    > > Var1, var2, 2
    > >
    > > is the Var1 from the left side of the input (row) or from the top row
    > > (column)?
    > >
    > >
    > > You show
    > > row var, column var, value
    > >
    > > (based on the value 2), but just to be sure.

    > Thanks for clarifying, yes this is correct.
    >
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > > "Dave" wrote:
    > >
    > > > Hello - I have a csv file in the form of a matrix with >256 variables (e.g.
    > > > 300 x 300) that I want to summarize to a column report. For example:
    > > >
    > > > Var1 Var2 Var3
    > > > Var1 1 2 3
    > > > Var2 4 5 6
    > > > Var3 7 8 9
    > > >
    > > >
    > > > And I would like the output to be:
    > > > Var1, Var1 1
    > > > Var1, Var2 2
    > > > Var1, Var3 3
    > > > Var2, Var1 4
    > > > Var2, Var2 5
    > > > Var2, Var3 6
    > > > Var3, Var1 7
    > > > Var3, Var2 8
    > > > Var3, Var3 9
    > > >
    > > > Anyone know of an easy way to do this in VBA?


  7. #7
    Dave
    Guest

    RE: Matrix to a Column Report

    Thanks, worked great!

    "Tom Ogilvy" wrote:

    > Sub convertData()
    > Dim ans As Long, hdr As Variant
    > Dim fName As Variant, s As String
    > Dim i As Long, j As Long
    > Dim ff As Long, ff1 As Long
    > Dim l1 As String, l As String
    > Dim v As Variant
    > Dim fName1 As String, sPath As String
    > ChDrive "C"
    > ChDir "C:\Chris"
    > fName = Application.GetOpenFilename("CSV Files (*.CSV),*.CSV")
    > If fName = False Then
    > Exit Sub
    > End If
    > fName1 = Replace(LCase(fName), ".csv", "_CONVERTED.csv")
    >
    > s = fName & vbNewLine & vbNewLine & _
    > "will be converted and results stored in " & _
    > vbNewLine & vbNewLine & fName1 & vbNewLine & _
    > vbNewLine & "Proceed?"
    > ans = MsgBox(Prompt:=s, _
    > Buttons:=vbYesNo + vbQuestion, _
    > Title:="Convert " & fName1)
    > If ans = vbNo Then
    > MsgBox "You chose to quit. Ending", vbCritical
    > Exit Sub
    > End If
    > ff = FreeFile()
    > Open fName For Input As ff
    > ff1 = FreeFile()
    > Open fName1 For Output As ff1
    > Line Input #ff, l1
    > hdr = Split(l1, ",")
    > Do While Not EOF(ff)
    > Line Input #ff, l
    > v = Split(l, ",")
    > For j = LBound(hdr) + 1 To UBound(hdr)
    > Print #ff1, v(LBound(v)) & "," & hdr(j) & "," & v(j)
    > Next j
    > Loop
    > Close #ff
    > Close #ff1
    > End Sub
    >
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Dave" wrote:
    >
    > > Hi Tom - Here are some answers to your questions:
    > >
    > > "Tom Ogilvy" wrote:
    > >
    > > > if it is 300 x 300, you would need to write out 90,000 rows, but there are
    > > > only 65,536

    > > Ya, I will then bring this new file into Access. I would bring the original
    > > file into Access but it has the 256 variable limitation as well.
    > >
    > > > is the first row and first column actually variable names.

    > > Yes
    > >
    > > > A CSV file usually means comma separated, but you show fixed width. What
    > > > does your file actually look like?

    > > Sorry, I should have been more specific. I just posted an answer to Ardus'
    > > question that shows an example of what my file actually looks like.
    > >
    > > > do you really need the result in excel or just write it back out to another
    > > > CSV file?

    > > Output to a .csv file would be great.
    > >
    > > >
    > > >
    > > > In your sample output,
    > > > Var1, var2, 2
    > > >
    > > > is the Var1 from the left side of the input (row) or from the top row
    > > > (column)?
    > > >
    > > >
    > > > You show
    > > > row var, column var, value
    > > >
    > > > (based on the value 2), but just to be sure.

    > > Thanks for clarifying, yes this is correct.
    > >
    > > >
    > > > --
    > > > Regards,
    > > > Tom Ogilvy
    > > >
    > > >
    > > > "Dave" wrote:
    > > >
    > > > > Hello - I have a csv file in the form of a matrix with >256 variables (e.g.
    > > > > 300 x 300) that I want to summarize to a column report. For example:
    > > > >
    > > > > Var1 Var2 Var3
    > > > > Var1 1 2 3
    > > > > Var2 4 5 6
    > > > > Var3 7 8 9
    > > > >
    > > > >
    > > > > And I would like the output to be:
    > > > > Var1, Var1 1
    > > > > Var1, Var2 2
    > > > > Var1, Var3 3
    > > > > Var2, Var1 4
    > > > > Var2, Var2 5
    > > > > Var2, Var3 6
    > > > > Var3, Var1 7
    > > > > Var3, Var2 8
    > > > > Var3, Var3 9
    > > > >
    > > > > Anyone know of an easy way to do this in VBA?


  8. #8
    Dave
    Guest

    RE: Matrix to a Column Report

    Hi Tom - Thanks again, I just have a follow up question, what if I wanted to
    only include the correlations that are greater than a certain value, say .4?
    Where would I add that code?

    "Tom Ogilvy" wrote:

    > Sub convertData()
    > Dim ans As Long, hdr As Variant
    > Dim fName As Variant, s As String
    > Dim i As Long, j As Long
    > Dim ff As Long, ff1 As Long
    > Dim l1 As String, l As String
    > Dim v As Variant
    > Dim fName1 As String, sPath As String
    > ChDrive "C"
    > ChDir "C:\Chris"
    > fName = Application.GetOpenFilename("CSV Files (*.CSV),*.CSV")
    > If fName = False Then
    > Exit Sub
    > End If
    > fName1 = Replace(LCase(fName), ".csv", "_CONVERTED.csv")
    >
    > s = fName & vbNewLine & vbNewLine & _
    > "will be converted and results stored in " & _
    > vbNewLine & vbNewLine & fName1 & vbNewLine & _
    > vbNewLine & "Proceed?"
    > ans = MsgBox(Prompt:=s, _
    > Buttons:=vbYesNo + vbQuestion, _
    > Title:="Convert " & fName1)
    > If ans = vbNo Then
    > MsgBox "You chose to quit. Ending", vbCritical
    > Exit Sub
    > End If
    > ff = FreeFile()
    > Open fName For Input As ff
    > ff1 = FreeFile()
    > Open fName1 For Output As ff1
    > Line Input #ff, l1
    > hdr = Split(l1, ",")
    > Do While Not EOF(ff)
    > Line Input #ff, l
    > v = Split(l, ",")
    > For j = LBound(hdr) + 1 To UBound(hdr)
    > Print #ff1, v(LBound(v)) & "," & hdr(j) & "," & v(j)
    > Next j
    > Loop
    > Close #ff
    > Close #ff1
    > End Sub
    >
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Dave" wrote:
    >
    > > Hi Tom - Here are some answers to your questions:
    > >
    > > "Tom Ogilvy" wrote:
    > >
    > > > if it is 300 x 300, you would need to write out 90,000 rows, but there are
    > > > only 65,536

    > > Ya, I will then bring this new file into Access. I would bring the original
    > > file into Access but it has the 256 variable limitation as well.
    > >
    > > > is the first row and first column actually variable names.

    > > Yes
    > >
    > > > A CSV file usually means comma separated, but you show fixed width. What
    > > > does your file actually look like?

    > > Sorry, I should have been more specific. I just posted an answer to Ardus'
    > > question that shows an example of what my file actually looks like.
    > >
    > > > do you really need the result in excel or just write it back out to another
    > > > CSV file?

    > > Output to a .csv file would be great.
    > >
    > > >
    > > >
    > > > In your sample output,
    > > > Var1, var2, 2
    > > >
    > > > is the Var1 from the left side of the input (row) or from the top row
    > > > (column)?
    > > >
    > > >
    > > > You show
    > > > row var, column var, value
    > > >
    > > > (based on the value 2), but just to be sure.

    > > Thanks for clarifying, yes this is correct.
    > >
    > > >
    > > > --
    > > > Regards,
    > > > Tom Ogilvy
    > > >
    > > >
    > > > "Dave" wrote:
    > > >
    > > > > Hello - I have a csv file in the form of a matrix with >256 variables (e.g.
    > > > > 300 x 300) that I want to summarize to a column report. For example:
    > > > >
    > > > > Var1 Var2 Var3
    > > > > Var1 1 2 3
    > > > > Var2 4 5 6
    > > > > Var3 7 8 9
    > > > >
    > > > >
    > > > > And I would like the output to be:
    > > > > Var1, Var1 1
    > > > > Var1, Var2 2
    > > > > Var1, Var3 3
    > > > > Var2, Var1 4
    > > > > Var2, Var2 5
    > > > > Var2, Var3 6
    > > > > Var3, Var1 7
    > > > > Var3, Var2 8
    > > > > Var3, Var3 9
    > > > >
    > > > > Anyone know of an easy way to do this in VBA?


  9. #9
    Dave
    Guest

    RE: Matrix to a Column Report

    ....nevermind, got it!

    "Dave" wrote:

    > Hi Tom - Thanks again, I just have a follow up question, what if I wanted to
    > only include the correlations that are greater than a certain value, say .4?
    > Where would I add that code?
    >
    > "Tom Ogilvy" wrote:
    >
    > > Sub convertData()
    > > Dim ans As Long, hdr As Variant
    > > Dim fName As Variant, s As String
    > > Dim i As Long, j As Long
    > > Dim ff As Long, ff1 As Long
    > > Dim l1 As String, l As String
    > > Dim v As Variant
    > > Dim fName1 As String, sPath As String
    > > ChDrive "C"
    > > ChDir "C:\Chris"
    > > fName = Application.GetOpenFilename("CSV Files (*.CSV),*.CSV")
    > > If fName = False Then
    > > Exit Sub
    > > End If
    > > fName1 = Replace(LCase(fName), ".csv", "_CONVERTED.csv")
    > >
    > > s = fName & vbNewLine & vbNewLine & _
    > > "will be converted and results stored in " & _
    > > vbNewLine & vbNewLine & fName1 & vbNewLine & _
    > > vbNewLine & "Proceed?"
    > > ans = MsgBox(Prompt:=s, _
    > > Buttons:=vbYesNo + vbQuestion, _
    > > Title:="Convert " & fName1)
    > > If ans = vbNo Then
    > > MsgBox "You chose to quit. Ending", vbCritical
    > > Exit Sub
    > > End If
    > > ff = FreeFile()
    > > Open fName For Input As ff
    > > ff1 = FreeFile()
    > > Open fName1 For Output As ff1
    > > Line Input #ff, l1
    > > hdr = Split(l1, ",")
    > > Do While Not EOF(ff)
    > > Line Input #ff, l
    > > v = Split(l, ",")
    > > For j = LBound(hdr) + 1 To UBound(hdr)
    > > Print #ff1, v(LBound(v)) & "," & hdr(j) & "," & v(j)
    > > Next j
    > > Loop
    > > Close #ff
    > > Close #ff1
    > > End Sub
    > >
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > > "Dave" wrote:
    > >
    > > > Hi Tom - Here are some answers to your questions:
    > > >
    > > > "Tom Ogilvy" wrote:
    > > >
    > > > > if it is 300 x 300, you would need to write out 90,000 rows, but there are
    > > > > only 65,536
    > > > Ya, I will then bring this new file into Access. I would bring the original
    > > > file into Access but it has the 256 variable limitation as well.
    > > >
    > > > > is the first row and first column actually variable names.
    > > > Yes
    > > >
    > > > > A CSV file usually means comma separated, but you show fixed width. What
    > > > > does your file actually look like?
    > > > Sorry, I should have been more specific. I just posted an answer to Ardus'
    > > > question that shows an example of what my file actually looks like.
    > > >
    > > > > do you really need the result in excel or just write it back out to another
    > > > > CSV file?
    > > > Output to a .csv file would be great.
    > > >
    > > > >
    > > > >
    > > > > In your sample output,
    > > > > Var1, var2, 2
    > > > >
    > > > > is the Var1 from the left side of the input (row) or from the top row
    > > > > (column)?
    > > > >
    > > > >
    > > > > You show
    > > > > row var, column var, value
    > > > >
    > > > > (based on the value 2), but just to be sure.
    > > > Thanks for clarifying, yes this is correct.
    > > >
    > > > >
    > > > > --
    > > > > Regards,
    > > > > Tom Ogilvy
    > > > >
    > > > >
    > > > > "Dave" wrote:
    > > > >
    > > > > > Hello - I have a csv file in the form of a matrix with >256 variables (e.g.
    > > > > > 300 x 300) that I want to summarize to a column report. For example:
    > > > > >
    > > > > > Var1 Var2 Var3
    > > > > > Var1 1 2 3
    > > > > > Var2 4 5 6
    > > > > > Var3 7 8 9
    > > > > >
    > > > > >
    > > > > > And I would like the output to be:
    > > > > > Var1, Var1 1
    > > > > > Var1, Var2 2
    > > > > > Var1, Var3 3
    > > > > > Var2, Var1 4
    > > > > > Var2, Var2 5
    > > > > > Var2, Var3 6
    > > > > > Var3, Var1 7
    > > > > > Var3, Var2 8
    > > > > > Var3, Var3 9
    > > > > >
    > > > > > Anyone know of an easy way to do this in VBA?


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1