Consulting

Results 1 to 9 of 9

Thread: Array Item used correctly

  1. #1
    VBAX Regular mikke3141's Avatar
    Joined
    Jun 2007
    Location
    Klaukkala
    Posts
    53
    Location

    Array Item used correctly

    Hello,

    I'm trying to populate the yellow cells with the same values as shown in the green cells using the dictionary object. What am I doing wrong?

    I appreciate your help.
    Attached Files Attached Files

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Regular mikke3141's Avatar
    Joined
    Jun 2007
    Location
    Klaukkala
    Posts
    53
    Location
    Thanks. I studied the content of the links to be able to get the content of the first array to the second. I tried with

    b = ActiveSheet.Range("J2:L9").Value
            For i = 1 To UBound(b, 1)
                If .Exists(b(i, 1)) Then
                 For ii = 1 To number_of_columns
              b(i, ii) = .Item(b(i, 1))(ii)
                    Next ii
             End If
          Next i
     End With
    but the b(i, ii) = .Item(b(i, 1))(ii) did not bring the content of the first array, but gives a type mismath error.

  4. #4
    VBAX Regular mikke3141's Avatar
    Joined
    Jun 2007
    Location
    Klaukkala
    Posts
    53
    Location
    b(i, ii) = a(b(i, 1), (ii))
    did not bring me any closer

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    b(i, ii) = a(b(i, 1), (ii))
    b(dimension, index) = a(dimension(index, index), (index))
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  6. #6
    VBAX Regular mikke3141's Avatar
    Joined
    Jun 2007
    Location
    Klaukkala
    Posts
    53
    Location
    I give up

  7. #7
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    This is meaningless
    a(b(i, 1), (ii))
    Show the entire code. What you showed in posts #3 and #4 is not enough.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  8. #8
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    You will have to put the values into the dictionary first
    b = ActiveSheet.Range("J2:L9").Value 
    with createobject("scripting.dictionary")
      For i = 1 To UBound(b, 1) 
        .item(b(i,1))=application.index(b,i)
      Next
      msgbox join(.item()(3))
    End With

  9. #9
    VBAX Regular mikke3141's Avatar
    Joined
    Jun 2007
    Location
    Klaukkala
    Posts
    53
    Location
    The code is

    Sub Start_It()
    
    number_of_columns = 2
    a = ActiveSheet.Range("A2:C30").Value
    With CreateObject("Scripting.Dictionary")
        For i = 1 To UBound(a, 1)
        .Item(a(i, 1)) = a(i, 1)
          For ii = 1 To number_of_columns
                    .Item(a(i, 1 + ii)) = a(i, 1 + ii)
          Next ii
        Next
    
    b = ActiveSheet.Range("J2:L9").Value
            For i = 1 To UBound(b, 1)
                If .Exists(b(i, 1)) Then
                 For ii = 1 To number_of_columns         
      b(i, ii) = a(b(i, 1), (ii)) 
            Next ii
             End If
          Next i
     End With
    
    ActiveSheet.Range("K2:L9").Value = b
    
    End Sub

Posting Permissions

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