Add items to Array in DictionaryHow to merge two dictionaries in a single expression?What is the best way to iterate over a dictionary?Create ArrayList from arrayHow to insert an item into an array at a specific index (JavaScript)?How do I sort a dictionary by value?Add new keys to a dictionary?Check if a given key already exists in a dictionaryIterating over dictionaries using 'for' loopsHow do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
Why aren't (poly-)cotton tents more popular?
What is this opening trap called, and how should I play afterwards? How can I refute the gambit, and play if I accept it?
What is an agent in Artificial Intelligence?
Does the UK have a written constitution?
How often can a PC check with passive perception during a combat turn?
Intuitively, why does putting capacitors in series decrease the equivalent capacitance?
Inverse-quotes-quine
How come I was asked by a CBP officer why I was in the US?
Story-based adventure with functions and relationships
How to get cool night-vision without lame drawbacks?
Layout of complex table
Swapping rooks in a 4x4 board
Counting occurrence of words in table is slow
What's the difference between 予定 (Yotei) and 計画 (keikaku)?
Can a US President have someone sent to prison?
How risky is real estate?
How to append a matrix element by element?
In the Marvel universe, can a human have a baby with any non-human?
Is it OK to bottle condition using previously contaminated bottles?
How should I behave to assure my friends that I am not after their money?
How well known and how commonly used was Huffman coding in 1979?
Do equal angles necessarily mean a polygon is regular?
MH370 blackbox - is it still possible to retrieve data from it?
Using “sparkling” as a diminutive of “spark” in a poem
Add items to Array in Dictionary
How to merge two dictionaries in a single expression?What is the best way to iterate over a dictionary?Create ArrayList from arrayHow to insert an item into an array at a specific index (JavaScript)?How do I sort a dictionary by value?Add new keys to a dictionary?Check if a given key already exists in a dictionaryIterating over dictionaries using 'for' loopsHow do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a dictionary and want to add new strings to the items. My idea is to create a list of strings as item for each key.
My code is so far:
Sub AccountEntitlements()
Dim sh1 As Worksheet
Dim acc As Worksheet
Dim arr() As Variant
Dim d As Variant
Dim i As Long
Dim count As Long
Set sh1 = Sheets("Sheet1")
Set acc = Sheets("accountsentitlements")
Set d = CreateObject("Scripting.Dictionary")
arr = sh1.Range("D:F")
For i = LBound(arr) To UBound(arr)
If d.Exists(arr(i, 3)) Then
ReDim Preserve arr(UBound(arr) + 1) '<- Error line
d(arr(i, 3)) = Array(arr(i, 1))
Else
d.Add Key:=arr(i, 3), Item:=Array(arr(i, 1))
End If
Next i
For count = 1 To d.count - 1
acc.Cells(count + 1, "D").Value = UCase(d.Keys()(count))
acc.Cells(count + 1, "E").Value = d.Items()(count)
Next count
End Sub
The error message is Run-time error '9': Subscript out of range.
The important code block is
For i = LBound(arr) To UBound(arr)
If d.Exists(arr(i, 3)) Then
ReDim Preserve arr(UBound(arr) + 1) '<- Error line
d(arr(i, 3)) = Array(arr(i, 1))
Else
d.Add Key:=arr(i, 3), Item:=Array(arr(i, 1))
End If
The key of a dictionary is the user account and the items should be their membership groups.
Example:
Key= ABCD , Item= Entitlement1, Entitlement2, etc.
How can the item array be extended and include previous entries?
arrays excel vba dictionary
|
show 2 more comments
I have a dictionary and want to add new strings to the items. My idea is to create a list of strings as item for each key.
My code is so far:
Sub AccountEntitlements()
Dim sh1 As Worksheet
Dim acc As Worksheet
Dim arr() As Variant
Dim d As Variant
Dim i As Long
Dim count As Long
Set sh1 = Sheets("Sheet1")
Set acc = Sheets("accountsentitlements")
Set d = CreateObject("Scripting.Dictionary")
arr = sh1.Range("D:F")
For i = LBound(arr) To UBound(arr)
If d.Exists(arr(i, 3)) Then
ReDim Preserve arr(UBound(arr) + 1) '<- Error line
d(arr(i, 3)) = Array(arr(i, 1))
Else
d.Add Key:=arr(i, 3), Item:=Array(arr(i, 1))
End If
Next i
For count = 1 To d.count - 1
acc.Cells(count + 1, "D").Value = UCase(d.Keys()(count))
acc.Cells(count + 1, "E").Value = d.Items()(count)
Next count
End Sub
The error message is Run-time error '9': Subscript out of range.
The important code block is
For i = LBound(arr) To UBound(arr)
If d.Exists(arr(i, 3)) Then
ReDim Preserve arr(UBound(arr) + 1) '<- Error line
d(arr(i, 3)) = Array(arr(i, 1))
Else
d.Add Key:=arr(i, 3), Item:=Array(arr(i, 1))
End If
The key of a dictionary is the user account and the items should be their membership groups.
Example:
Key= ABCD , Item= Entitlement1, Entitlement2, etc.
How can the item array be extended and include previous entries?
arrays excel vba dictionary
1
Use a Dictionary or Collection instead of an array to hold the membership groups. And why create such a large array to loop through in the first place?
– Ron Rosenfeld
Mar 25 at 10:36
2
The error is because you can onlyRedim Preservethe last element of a multidimensional array. Since you alreadyarr= Range("D:F"), and yourRedim Preserve arr(...` statement must fail. It is NOT acting on the array in the Dictionary.
– Ron Rosenfeld
Mar 25 at 10:42
@RonRosenfeld, what do you mean with 'such a large array'? How would you split the array?
– Alex_P
Mar 25 at 10:59
1
arr = Range("D:F")creates an array of dimensions(1 to 1048576, 1 to 4). Do you have that many items in your database? For a good discussion, see the late Chip Pearsons article on Arrays and Ranges in VBA
– Ron Rosenfeld
Mar 25 at 11:02
@RonRosenfeld, I have 81.000 rows. Thank you for the link. I will check it out.
– Alex_P
Mar 25 at 11:04
|
show 2 more comments
I have a dictionary and want to add new strings to the items. My idea is to create a list of strings as item for each key.
My code is so far:
Sub AccountEntitlements()
Dim sh1 As Worksheet
Dim acc As Worksheet
Dim arr() As Variant
Dim d As Variant
Dim i As Long
Dim count As Long
Set sh1 = Sheets("Sheet1")
Set acc = Sheets("accountsentitlements")
Set d = CreateObject("Scripting.Dictionary")
arr = sh1.Range("D:F")
For i = LBound(arr) To UBound(arr)
If d.Exists(arr(i, 3)) Then
ReDim Preserve arr(UBound(arr) + 1) '<- Error line
d(arr(i, 3)) = Array(arr(i, 1))
Else
d.Add Key:=arr(i, 3), Item:=Array(arr(i, 1))
End If
Next i
For count = 1 To d.count - 1
acc.Cells(count + 1, "D").Value = UCase(d.Keys()(count))
acc.Cells(count + 1, "E").Value = d.Items()(count)
Next count
End Sub
The error message is Run-time error '9': Subscript out of range.
The important code block is
For i = LBound(arr) To UBound(arr)
If d.Exists(arr(i, 3)) Then
ReDim Preserve arr(UBound(arr) + 1) '<- Error line
d(arr(i, 3)) = Array(arr(i, 1))
Else
d.Add Key:=arr(i, 3), Item:=Array(arr(i, 1))
End If
The key of a dictionary is the user account and the items should be their membership groups.
Example:
Key= ABCD , Item= Entitlement1, Entitlement2, etc.
How can the item array be extended and include previous entries?
arrays excel vba dictionary
I have a dictionary and want to add new strings to the items. My idea is to create a list of strings as item for each key.
My code is so far:
Sub AccountEntitlements()
Dim sh1 As Worksheet
Dim acc As Worksheet
Dim arr() As Variant
Dim d As Variant
Dim i As Long
Dim count As Long
Set sh1 = Sheets("Sheet1")
Set acc = Sheets("accountsentitlements")
Set d = CreateObject("Scripting.Dictionary")
arr = sh1.Range("D:F")
For i = LBound(arr) To UBound(arr)
If d.Exists(arr(i, 3)) Then
ReDim Preserve arr(UBound(arr) + 1) '<- Error line
d(arr(i, 3)) = Array(arr(i, 1))
Else
d.Add Key:=arr(i, 3), Item:=Array(arr(i, 1))
End If
Next i
For count = 1 To d.count - 1
acc.Cells(count + 1, "D").Value = UCase(d.Keys()(count))
acc.Cells(count + 1, "E").Value = d.Items()(count)
Next count
End Sub
The error message is Run-time error '9': Subscript out of range.
The important code block is
For i = LBound(arr) To UBound(arr)
If d.Exists(arr(i, 3)) Then
ReDim Preserve arr(UBound(arr) + 1) '<- Error line
d(arr(i, 3)) = Array(arr(i, 1))
Else
d.Add Key:=arr(i, 3), Item:=Array(arr(i, 1))
End If
The key of a dictionary is the user account and the items should be their membership groups.
Example:
Key= ABCD , Item= Entitlement1, Entitlement2, etc.
How can the item array be extended and include previous entries?
arrays excel vba dictionary
arrays excel vba dictionary
asked Mar 25 at 10:20
Alex_PAlex_P
3451 gold badge4 silver badges15 bronze badges
3451 gold badge4 silver badges15 bronze badges
1
Use a Dictionary or Collection instead of an array to hold the membership groups. And why create such a large array to loop through in the first place?
– Ron Rosenfeld
Mar 25 at 10:36
2
The error is because you can onlyRedim Preservethe last element of a multidimensional array. Since you alreadyarr= Range("D:F"), and yourRedim Preserve arr(...` statement must fail. It is NOT acting on the array in the Dictionary.
– Ron Rosenfeld
Mar 25 at 10:42
@RonRosenfeld, what do you mean with 'such a large array'? How would you split the array?
– Alex_P
Mar 25 at 10:59
1
arr = Range("D:F")creates an array of dimensions(1 to 1048576, 1 to 4). Do you have that many items in your database? For a good discussion, see the late Chip Pearsons article on Arrays and Ranges in VBA
– Ron Rosenfeld
Mar 25 at 11:02
@RonRosenfeld, I have 81.000 rows. Thank you for the link. I will check it out.
– Alex_P
Mar 25 at 11:04
|
show 2 more comments
1
Use a Dictionary or Collection instead of an array to hold the membership groups. And why create such a large array to loop through in the first place?
– Ron Rosenfeld
Mar 25 at 10:36
2
The error is because you can onlyRedim Preservethe last element of a multidimensional array. Since you alreadyarr= Range("D:F"), and yourRedim Preserve arr(...` statement must fail. It is NOT acting on the array in the Dictionary.
– Ron Rosenfeld
Mar 25 at 10:42
@RonRosenfeld, what do you mean with 'such a large array'? How would you split the array?
– Alex_P
Mar 25 at 10:59
1
arr = Range("D:F")creates an array of dimensions(1 to 1048576, 1 to 4). Do you have that many items in your database? For a good discussion, see the late Chip Pearsons article on Arrays and Ranges in VBA
– Ron Rosenfeld
Mar 25 at 11:02
@RonRosenfeld, I have 81.000 rows. Thank you for the link. I will check it out.
– Alex_P
Mar 25 at 11:04
1
1
Use a Dictionary or Collection instead of an array to hold the membership groups. And why create such a large array to loop through in the first place?
– Ron Rosenfeld
Mar 25 at 10:36
Use a Dictionary or Collection instead of an array to hold the membership groups. And why create such a large array to loop through in the first place?
– Ron Rosenfeld
Mar 25 at 10:36
2
2
The error is because you can only
Redim Preserve the last element of a multidimensional array. Since you already arr= Range("D:F"), and your Redim Preserve arr(...` statement must fail. It is NOT acting on the array in the Dictionary.– Ron Rosenfeld
Mar 25 at 10:42
The error is because you can only
Redim Preserve the last element of a multidimensional array. Since you already arr= Range("D:F"), and your Redim Preserve arr(...` statement must fail. It is NOT acting on the array in the Dictionary.– Ron Rosenfeld
Mar 25 at 10:42
@RonRosenfeld, what do you mean with 'such a large array'? How would you split the array?
– Alex_P
Mar 25 at 10:59
@RonRosenfeld, what do you mean with 'such a large array'? How would you split the array?
– Alex_P
Mar 25 at 10:59
1
1
arr = Range("D:F") creates an array of dimensions (1 to 1048576, 1 to 4). Do you have that many items in your database? For a good discussion, see the late Chip Pearsons article on Arrays and Ranges in VBA– Ron Rosenfeld
Mar 25 at 11:02
arr = Range("D:F") creates an array of dimensions (1 to 1048576, 1 to 4). Do you have that many items in your database? For a good discussion, see the late Chip Pearsons article on Arrays and Ranges in VBA– Ron Rosenfeld
Mar 25 at 11:02
@RonRosenfeld, I have 81.000 rows. Thank you for the link. I will check it out.
– Alex_P
Mar 25 at 11:04
@RonRosenfeld, I have 81.000 rows. Thank you for the link. I will check it out.
– Alex_P
Mar 25 at 11:04
|
show 2 more comments
2 Answers
2
active
oldest
votes
Among other problems:
You can only ReDim the last element of a multi-dimensional array.
Your line
arr = sh1.Range("D:F")
will create a 1-based 2D array: arr(1 to 1048576, 1 to 4). If you have a database with over 4*10^6 elements, you might want to consider a different tool.
So a valid command might be
Redim Preserve arr(1 to ubound(arr,1), 1 to ubound(arr,2)+1)
But that's not what your doing. To accomplish what you want to do, try something like this:
For i = LBound(arr) To UBound(arr)
If d.Exists(arr(i, 3)) Then
X = d(arr(i, 3))
ReDim Preserve X(UBound(X, 1) + 1)
X(UBound(X, 1)) = arr(i, 1)
d(arr(i, 3)) = X
Else
d.Add Key:=arr(i, 3), Item:=Array(arr(i, 1))
End If
Next i
But why not just use a Dictionary or Collection to hold your list of items. Then you don't have to worry at all about resizing your array.
add a comment |
Thank you very much for your assistance (@Ron Rosenfeld)!
Below is my final code part.
For i = LBound(arr) To UBound(arr)
If d.Exists(arr(i, 3)) Then
d(arr(i, 3)) = d.Item(arr(i, 3)) & "," & arr(i, 1)
Else
d.Add Key:=arr(i, 3), Item:=arr(i, 1)
End If
Next i
I was still testing whether I should concatenate the strings with & "," & or with the JOIN() function but decided eventually for the first option.
Regarding my array size, I added a row counter to fit the length of the array. lrow = sh1.Cells(Rows.count, "D").End(xlUp).Row.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55335581%2fadd-items-to-array-in-dictionary%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Among other problems:
You can only ReDim the last element of a multi-dimensional array.
Your line
arr = sh1.Range("D:F")
will create a 1-based 2D array: arr(1 to 1048576, 1 to 4). If you have a database with over 4*10^6 elements, you might want to consider a different tool.
So a valid command might be
Redim Preserve arr(1 to ubound(arr,1), 1 to ubound(arr,2)+1)
But that's not what your doing. To accomplish what you want to do, try something like this:
For i = LBound(arr) To UBound(arr)
If d.Exists(arr(i, 3)) Then
X = d(arr(i, 3))
ReDim Preserve X(UBound(X, 1) + 1)
X(UBound(X, 1)) = arr(i, 1)
d(arr(i, 3)) = X
Else
d.Add Key:=arr(i, 3), Item:=Array(arr(i, 1))
End If
Next i
But why not just use a Dictionary or Collection to hold your list of items. Then you don't have to worry at all about resizing your array.
add a comment |
Among other problems:
You can only ReDim the last element of a multi-dimensional array.
Your line
arr = sh1.Range("D:F")
will create a 1-based 2D array: arr(1 to 1048576, 1 to 4). If you have a database with over 4*10^6 elements, you might want to consider a different tool.
So a valid command might be
Redim Preserve arr(1 to ubound(arr,1), 1 to ubound(arr,2)+1)
But that's not what your doing. To accomplish what you want to do, try something like this:
For i = LBound(arr) To UBound(arr)
If d.Exists(arr(i, 3)) Then
X = d(arr(i, 3))
ReDim Preserve X(UBound(X, 1) + 1)
X(UBound(X, 1)) = arr(i, 1)
d(arr(i, 3)) = X
Else
d.Add Key:=arr(i, 3), Item:=Array(arr(i, 1))
End If
Next i
But why not just use a Dictionary or Collection to hold your list of items. Then you don't have to worry at all about resizing your array.
add a comment |
Among other problems:
You can only ReDim the last element of a multi-dimensional array.
Your line
arr = sh1.Range("D:F")
will create a 1-based 2D array: arr(1 to 1048576, 1 to 4). If you have a database with over 4*10^6 elements, you might want to consider a different tool.
So a valid command might be
Redim Preserve arr(1 to ubound(arr,1), 1 to ubound(arr,2)+1)
But that's not what your doing. To accomplish what you want to do, try something like this:
For i = LBound(arr) To UBound(arr)
If d.Exists(arr(i, 3)) Then
X = d(arr(i, 3))
ReDim Preserve X(UBound(X, 1) + 1)
X(UBound(X, 1)) = arr(i, 1)
d(arr(i, 3)) = X
Else
d.Add Key:=arr(i, 3), Item:=Array(arr(i, 1))
End If
Next i
But why not just use a Dictionary or Collection to hold your list of items. Then you don't have to worry at all about resizing your array.
Among other problems:
You can only ReDim the last element of a multi-dimensional array.
Your line
arr = sh1.Range("D:F")
will create a 1-based 2D array: arr(1 to 1048576, 1 to 4). If you have a database with over 4*10^6 elements, you might want to consider a different tool.
So a valid command might be
Redim Preserve arr(1 to ubound(arr,1), 1 to ubound(arr,2)+1)
But that's not what your doing. To accomplish what you want to do, try something like this:
For i = LBound(arr) To UBound(arr)
If d.Exists(arr(i, 3)) Then
X = d(arr(i, 3))
ReDim Preserve X(UBound(X, 1) + 1)
X(UBound(X, 1)) = arr(i, 1)
d(arr(i, 3)) = X
Else
d.Add Key:=arr(i, 3), Item:=Array(arr(i, 1))
End If
Next i
But why not just use a Dictionary or Collection to hold your list of items. Then you don't have to worry at all about resizing your array.
edited Mar 25 at 11:00
answered Mar 25 at 10:34
Ron RosenfeldRon Rosenfeld
25.6k4 gold badges17 silver badges41 bronze badges
25.6k4 gold badges17 silver badges41 bronze badges
add a comment |
add a comment |
Thank you very much for your assistance (@Ron Rosenfeld)!
Below is my final code part.
For i = LBound(arr) To UBound(arr)
If d.Exists(arr(i, 3)) Then
d(arr(i, 3)) = d.Item(arr(i, 3)) & "," & arr(i, 1)
Else
d.Add Key:=arr(i, 3), Item:=arr(i, 1)
End If
Next i
I was still testing whether I should concatenate the strings with & "," & or with the JOIN() function but decided eventually for the first option.
Regarding my array size, I added a row counter to fit the length of the array. lrow = sh1.Cells(Rows.count, "D").End(xlUp).Row.
add a comment |
Thank you very much for your assistance (@Ron Rosenfeld)!
Below is my final code part.
For i = LBound(arr) To UBound(arr)
If d.Exists(arr(i, 3)) Then
d(arr(i, 3)) = d.Item(arr(i, 3)) & "," & arr(i, 1)
Else
d.Add Key:=arr(i, 3), Item:=arr(i, 1)
End If
Next i
I was still testing whether I should concatenate the strings with & "," & or with the JOIN() function but decided eventually for the first option.
Regarding my array size, I added a row counter to fit the length of the array. lrow = sh1.Cells(Rows.count, "D").End(xlUp).Row.
add a comment |
Thank you very much for your assistance (@Ron Rosenfeld)!
Below is my final code part.
For i = LBound(arr) To UBound(arr)
If d.Exists(arr(i, 3)) Then
d(arr(i, 3)) = d.Item(arr(i, 3)) & "," & arr(i, 1)
Else
d.Add Key:=arr(i, 3), Item:=arr(i, 1)
End If
Next i
I was still testing whether I should concatenate the strings with & "," & or with the JOIN() function but decided eventually for the first option.
Regarding my array size, I added a row counter to fit the length of the array. lrow = sh1.Cells(Rows.count, "D").End(xlUp).Row.
Thank you very much for your assistance (@Ron Rosenfeld)!
Below is my final code part.
For i = LBound(arr) To UBound(arr)
If d.Exists(arr(i, 3)) Then
d(arr(i, 3)) = d.Item(arr(i, 3)) & "," & arr(i, 1)
Else
d.Add Key:=arr(i, 3), Item:=arr(i, 1)
End If
Next i
I was still testing whether I should concatenate the strings with & "," & or with the JOIN() function but decided eventually for the first option.
Regarding my array size, I added a row counter to fit the length of the array. lrow = sh1.Cells(Rows.count, "D").End(xlUp).Row.
answered Mar 26 at 8:58
Alex_PAlex_P
3451 gold badge4 silver badges15 bronze badges
3451 gold badge4 silver badges15 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55335581%2fadd-items-to-array-in-dictionary%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Use a Dictionary or Collection instead of an array to hold the membership groups. And why create such a large array to loop through in the first place?
– Ron Rosenfeld
Mar 25 at 10:36
2
The error is because you can only
Redim Preservethe last element of a multidimensional array. Since you alreadyarr= Range("D:F"), and yourRedim Preserve arr(...` statement must fail. It is NOT acting on the array in the Dictionary.– Ron Rosenfeld
Mar 25 at 10:42
@RonRosenfeld, what do you mean with 'such a large array'? How would you split the array?
– Alex_P
Mar 25 at 10:59
1
arr = Range("D:F")creates an array of dimensions(1 to 1048576, 1 to 4). Do you have that many items in your database? For a good discussion, see the late Chip Pearsons article on Arrays and Ranges in VBA– Ron Rosenfeld
Mar 25 at 11:02
@RonRosenfeld, I have 81.000 rows. Thank you for the link. I will check it out.
– Alex_P
Mar 25 at 11:04