Results 1 to 7 of 7

Thread: [RESOLVED] Help with Transpose

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Resolved [RESOLVED] Help with Transpose

    I have an array called "Result" that contains a variable number of columns and 252 rows. Assuming there are 2 columns I'd like to use Transpose to place the array into column CJ where the array columns are are concatenated. For example if Result(0,0) is 66 and Result(1,0) = 52 then CJ1 should be 6652. The concatenation of Result(0,1) is 66 and Result(1,1) should follow that, etc.

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,264

    Re: Help with Transpose

    What about 3 (or more) columns?

    Result(0,0)=66
    Result(1,0)=52
    Result(2,0)=18

    should then be "665218" in CJ1?
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3

  4. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,264

    Re: Help with Transpose

    Questions:
    1) are we talking VBA or Excel functions?
    2) the values in that array are all longs?
    3) 1st dimension is rows, 2nd columns?
    4) any ready to use bogus sample-data?
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  5. #5

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Help with Transpose

    I need VBA.

    The array looks like this (truncated).
    Name:  2023-03-14_12-43-30.jpg
Views: 140
Size:  27.4 KB

    The values in the array are the result of generating all the combinations of several numbers like 66 52 59 17 15 70 38 30 24 16 14 taken 2 at a time. In some situations I need to take them 3, 4, 5 etc at a time.

    It also would be very useful later on to be able to calculate the "54" value.

  6. #6
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,264

    Re: Help with Transpose

    Quick and dirty
    Code:
    Sub main()
    '4 Rows, 10 Columns
    Dim Result(0 To 3, 0 To 9) As Long
    Dim t() As String
    Dim i As Long
    Dim j As Long
    Dim s As String
        'Init some Bogus-Data
        For i = 0 To 9
            Result(0, i) = 66
            'Random Integers between 10 and 99
            Result(1, i) = Int(10 + Rnd * 90)
            Result(2, i) = Int(10 + Rnd * 90)
            Result(3, i) = Int(10 + Rnd * 90)
        Next
        ReDim t(0 To UBound(Result, 1)) 'Get Ubound of Rows
        For j = 0 To UBound(Result, 2)  'Get UBound of Columns
            For i = 0 To UBound(t)
                t(i) = CStr(Result(i, j))
            Next
            s = Join(t, "")             'Assign "s" to your target-cell
            Debug.Print s
        Next
    End Sub
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  7. #7

Posting Permissions

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



Click Here to Expand Forum to Full Width