+ Reply to Thread
Results 1 to 14 of 14

add one dimension to array

Hybrid View

shaykos add one dimension to array 12-03-2015, 02:31 AM
shg Re: add one dimension to array 12-03-2015, 03:00 AM
shaykos Re: add one dimension to array 12-03-2015, 02:51 PM
Norie Re: add one dimension to array 12-03-2015, 02:53 PM
jindon Re: add one dimension to array 12-03-2015, 04:12 PM
shaykos Re: add one dimension to array 12-04-2015, 04:39 PM
jindon Re: add one dimension to array 12-04-2015, 05:51 PM
shaykos Re: add one dimension to array 12-04-2015, 07:38 PM
jindon Re: add one dimension to array 12-04-2015, 08:08 PM
shaykos Re: add one dimension to array 12-04-2015, 08:43 PM
jindon Re: add one dimension to array 12-04-2015, 08:47 PM
shaykos Re: add one dimension to array 12-04-2015, 09:09 PM
jindon Re: add one dimension to array 12-04-2015, 09:42 PM
shaykos Re: add one dimension to array 12-04-2015, 10:47 PM
  1. #1
    Registered User
    Join Date
    10-04-2014
    Location
    israel
    MS-Off Ver
    2010
    Posts
    24

    add one dimension to array

    hi

    i want to add one dimension to an array
    here is part of the code

    sub Add_dimansion()
    
    dim Y() as string
    y()=split("1,2,3,4,5,6,7,8,9",",")        ' here i have one dimension array with 10 elements
    for i=0 to Ubound(y)                     ' for i=0 to the last element number of the Y() array
    Array2(0,i)=Y(i)                           'now i am just want to create a new 2 dimensional array(in this case the first element is 0 and only the second changed)  
    next i
    end sub
    any way...i receive an error
    any help?

    thanks
    Last edited by shaykos; 12-03-2015 at 02:48 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: add one dimension to array

    Please take a few minutes to re-read the forum rules, and then edit your post to add CODE tags.

    Thanks.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    10-04-2014
    Location
    israel
    MS-Off Ver
    2010
    Posts
    24

    Re: add one dimension to array

    yes sir haha

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: add one dimension to array

    You haven't dimensioned Array2.
    If posting code please use code tags, see here.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: add one dimension to array

    Array2=application.transpose(y)
    Converts 1D array to 1 Based 2D array.

  6. #6
    Registered User
    Join Date
    10-04-2014
    Location
    israel
    MS-Off Ver
    2010
    Posts
    24

    Re: add one dimension to array

    hi
    sorry for that but i still dont understand this method(only when paste vertical to horizontal and vice versa)
    can u show me the full code to convert one dimension array to 2D?
    column A is identifier(one number) and the the B column(same row) is data breaks by commas(1,4,3,2,4,0,0,0,3,2...)
    i just want for each of those rows to make column A as the first dimension(the number of elements is the rows number) and the second dimension is the data in column B

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: add one dimension to array

    Ahhh, you want it as
    Array2(0,i)=Y(i)
    But why do you need it so?

    Transpose will give you
    Array2(i,1)=Y(i)
    So this is not what you want.

  8. #8
    Registered User
    Join Date
    10-04-2014
    Location
    israel
    MS-Off Ver
    2010
    Posts
    24

    Re: add one dimension to array

    still got en error with this
    I'll give an example for what i need(suppose to be simple to do that)
    column A____ column B
    1 __________ 1,2,3,4,5....
    2 __________ 11,22,33,44,55...
    3 __________ 4,6,7,6,5,4,3,....
    4 __________ 1,3,5,7,8,0,3,4,2,....

    now i just want to call for example to Array2(3,5)
    and it should give me the 0
    Last edited by shaykos; 12-04-2015 at 07:40 PM.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: add one dimension to array

    I don't understand why you need it an array...

    I would do like
        With Range("b1", Range("b" & Rows.Count).End(xlUp))
            MsgBox Split(.Cells(3, 1), ",")(5)
        End With

  10. #10
    Registered User
    Join Date
    10-04-2014
    Location
    israel
    MS-Off Ver
    2010
    Posts
    24

    Re: add one dimension to array

    i heard that arrays works much faster than others methods
    actually it's a game results
    each row is a player
    the "1,3,2,4,0,3,2,..." (column B) is the answers of the player for each question
    finally i want to know the percentages for each answer for each question
    after i got an array(x,y) ; x-index of player ; y-all the answers
    i'll be able to continue with the calculations(and there are a lot of games)

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: add one dimension to array

    It depends how you use it.
    In your case, it is not much difference.

  12. #12
    Registered User
    Join Date
    10-04-2014
    Location
    israel
    MS-Off Ver
    2010
    Posts
    24

    Re: add one dimension to array

    the issue is that i need that array for calculation
    simple example: only one game, only 4 players,only 4 questions,only 4 answers for each question:
    after i get the array i want to do:
    ub = UBound(Y())
    a1 = 0: a2 = 0: a3 = 0: a4 = 0
    For Q = 0 To ub '_________its the index of the questions
    For P0 = 0 To P '_________actually its the rows(the players)
    Answer = Array(P0, Q) '________ actually its Array(Player, question_index)
    If Answer = 1 Then
    a1 = a1 + 1
    ElseIf Answer = 2 Then
    a2 = a2 + 1
    ElseIf Answer = 3 Then
    a3 = a3 + 1
    ElseIf Answer = 4 Then
    a4 = a4 + 1
    End If
    Next P0 '______next row(player)
    Result(Q, 0) = a1 'now its assign to new array the how many respond to each answer of the question
    Result(Q, 1) = a2
    Result(Q, 2) = a3
    Result(Q, 3) = a4
    Next Q

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: add one dimension to array

    If you upload a workbook with data and the result taht you want, it may help understanding what you are trying to do.
    However, reading your code is not understandable.

    If you know about array, you should have loaded the data with loop or even manually, because it is 0 based.
    So how would I know what you want to do?

  14. #14
    Registered User
    Join Date
    10-04-2014
    Location
    israel
    MS-Off Ver
    2010
    Posts
    24

    Re: add one dimension to array

    ok...i think i got it
    the issue was because i have to declare number of elements to the array...something with "Redim"

    Sub game()
    
    Dim Q() As String
    Dim Player, i, UB As Variant
    Player = -1
    Row = 2
    Q_No = Split(Range("B" & Row), ",")
    UB = UBound(Q_No)
    ReDim Answer(400, UB) As String
         Do While Range("A" & Row) = Range("A" & (Row - 1))
                 Player = Player + 1
                 Q() = Split(Range("B" & Row), ",")
                 For i = 0 To UB
                 Answer(Player, i) = Q(i)
        
                 Next i
                 Row = Row + 1
         Loop
    
    MsgBox Answer(399, 32)
    
    MsgBox Answer(398, 31)
    
    End Sub
    its not clean but it work now (based on my worksheet data)

    Thanks u for the effort

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel: Sum each dimension of an Array
    By cmore in forum Excel Programming / VBA / Macros
    Replies: 42
    Last Post: 06-08-2015, 11:35 PM
  2. [SOLVED] Sort a 2 dimension array
    By tradinup2 in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 02-28-2013, 10:29 AM
  3. Does filling part of an array from a range re-dimension the array?
    By barryleajo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-04-2011, 10:09 AM
  4. Cycling through 1 dimension of an array
    By Phil_V in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-17-2009, 09:51 AM
  5. Array dimension declaration
    By yellephant in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-29-2007, 08:44 AM
  6. Array dimension
    By Henrietta Klaus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-21-2006, 11:10 AM
  7. [SOLVED] Mutli-dimensional Array to Single-Dimension Array
    By Blue Aardvark in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-15-2005, 05:05 AM

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