Add array elements to dictionary

Tejas Kore

Board Regular
Joined
Nov 2, 2017
Messages
72
Office Version
  1. 365
Platform
  1. Windows
Hi Friends,

I am facing a error "Subscript out of range".
I am trying to add array names to dictionary.

column_arr_1 = Array("X1", "Y2")
column_arr_2 = Array("Z3", "A1")
column_arr_3 = Array("B1", "C1")
column_arr = Array(column_arr_1, column_arr_2, column_arr_3)

For i = 1 To UBound(column_arr) - LBound(column_arr) + 1
a.Add i, column_arr(i)
Next i

I am unable to understand where I am commiting the mistake ?
Is there any alternative to do this ?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hello,

this is my example (based on snb code):

Code:
Sub test()
sn = Cells(1).CurrentRegion
With CreateObject("scripting.dictionary")
    For i = 2 To UBound(sn)
        c00 = sn(i, 1)
        If Not .exists(c00) Then
            .Item(c00) = Array(sn(i, 1), sn(i, 2), sn(i, 3))
        End If
    Next i
    Cells(2, 5).Resize(.Count, 3) = Application.Index(.items, 0, 0)
End With
End Sub

Maybe it helps.

regards
 
Upvote 0
Hi Friends,

I am facing a error "Subscript out of range".
I am trying to add array names to dictionary.

column_arr_1 = Array("X1", "Y2")
column_arr_2 = Array("Z3", "A1")
column_arr_3 = Array("B1", "C1")
column_arr = Array(column_arr_1, column_arr_2, column_arr_3)

For i = 1 To UBound(column_arr) - LBound(column_arr) + 1
a.Add i, column_arr(i)
Next i

I am unable to understand where I am commiting the mistake ?
Is there any alternative to do this ?


Maybe with this adjustment

Code:
For i = 1 To UBound(column_arr) - LBound(column_arr) + 1
    a.Add i, column_arr(i [COLOR=#ff0000]- 1[/COLOR])
Next i

M.
 
Upvote 0
Thanks a LOT Marcelo !!!
It worked perfectly fine.
I guess u r a REAL MADRID fan :)
 
Upvote 0
You are welcome. Glad to help :)

Real Madrid vs Gremio tomorrow. Real Madrid is a much better team and must win, but in football you never know what will happen.
I live in Rio and I support Fluminense - a traditional team full of glories :)
But at the moment going through financial problems and not being able to hire good players. :(

All the best

M.
 
Upvote 0

Forum statistics

Threads
1,215,465
Messages
6,124,977
Members
449,200
Latest member
Jamil ahmed

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top