Array assignment help

vbanative

New Member
Joined
Mar 30, 2013
Messages
8
I have the following code running. However, the array Segments is not getting population when i run the assignment line below.

Dim CurrentSegment As Variant
ReDim Segments(0) As Variant
MsgBox CurrentSegment
Segments(UBound(Segments)) = CurrentSegments
MsgBox (Segments(UBound(Segments)))

The result of the first MsgBox is a number, 8700000, but the result of the second msgbox is an empty set. Any ideas why array element will not take on the value of CurrentSegments? Any help would be greatly appreciated.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I have the following code running. However, the array Segments is not getting population when i run the assignment line below.

Dim CurrentSegment As Variant
ReDim Segments(0) As Variant
MsgBox CurrentSegment
Segments(UBound(Segments)) = CurrentSegments
MsgBox (Segments(UBound(Segments)))

The result of the first MsgBox is a number, 8700000, but the result of the second msgbox is an empty set. Any ideas why array element will not take on the value of CurrentSegments? Any help would be greatly appreciated.
I think we need some more details about what you have and what you want from it. For example... What is CurrentSegment (range assignment, variable assigned elsewhere, etc.), how and when did it get a value of 8700000? What do you expect Segments to be (a single element or multi-element array and how is it to be fully populated) and how do you plan on using it later? Those are only two questions that come to mind immediately... the point being, we know nothing about what you have or what you want to do with it... you can't just take a small piece out of it without explanation and expect someone to be able to follow along.
 
Upvote 0
I think we need some more details about what you have and what you want from it. For example... What is CurrentSegment (range assignment, variable assigned elsewhere, etc.), how and when did it get a value of 8700000? What do you expect Segments to be (a single element or multi-element array and how is it to be fully populated) and how do you plan on using it later? Those are only two questions that come to mind immediately... the point being, we know nothing about what you have or what you want to do with it... you can't just take a small piece out of it without explanation and expect someone to be able to follow along.

Thanks Rick. CurrentSegment is a variant variable type. It assumes a new value each time a for loop is run. Each time it goes through the for loop, I want to store its value in a multi-value array. However, the assignment statement shown above is not successful. As indicated by the messagebox, it has the value 8700000. Yet, after the assignment statement, segments does not take on this value. I plan on extracting each element out of Segments and running some bit-wise operations on it. Hope this helps and I appreciate your response.
 
Upvote 0
Thanks Rick. CurrentSegment is a variant variable type. It assumes a new value each time a for loop is run. Each time it goes through the for loop, I want to store its value in a multi-value array. However, the assignment statement shown above is not successful. As indicated by the messagebox, it has the value 8700000. Yet, after the assignment statement, segments does not take on this value. I plan on extracting each element out of Segments and running some bit-wise operations on it. Hope this helps and I appreciate your response.
Why don't you show us the loop itself (or even better, your complete code) so we can provide you with a working answer that you will not have to try and modify.
 
Upvote 0

Forum statistics

Threads
1,203,099
Messages
6,053,527
Members
444,669
Latest member
Renarian

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