Does ReDim Autoinitialize To 0?
Apr 26, 2006Does using ReDim to size an array also initialize all array elements to zero by default? If not, is there a quick way to autoinitialize all array elements to zero?
View 2 RepliesDoes using ReDim to size an array also initialize all array elements to zero by default? If not, is there a quick way to autoinitialize all array elements to zero?
View 2 RepliesI iterate through a list and store the data in an array.
[Code] ..........
This works fine, but I tried to have 2 dimensions to the array and It no longer works!
I want to have an array where each record contains a name and three numbers. My understanding is that Excel requires all element types within an array to be the same, and so I turned to a user-defined data type. But I don't seem to be able to create a dynamic array out of this type--when I try to ReDim Preserve it, I get an error saying that it's already defined. Can't I do that?
View 3 Replies View RelatedCurrently I am building a class to keep track of entries I have made during the macro execution. Thus far I have:
Private Type Memory
MemoryArray() As Variant
End Type
Private Sub Class_Initialize()
Redim MemoryArray(0) As Variant
End Sub
Public Property Let AddToMemory(Object As Variant)
'memory is empty
If UBound(MemoryArray) = 0 And MemoryArray(UBound(MemoryArray)) = "" Then
MemoryArray(0) = Object ..............
I have: ReDim X(3,1) as double. The code runs fine on my machine, but when I take it to another machine, the code gets stuck on that line.
View 3 Replies View RelatedI have an array that is going to have a variable length every time the macro is run. I set a really high length at the beginning and when I want to unload the data, I want to redim the array to only the amount of data that was loaded into the array.
I am getting an error of "Array already dimensioned" when use the redim function near the end of my code below.
Code:
Private Sub Trend_Click()Dim GraphRow As LongDim TodaysYear As Integer,
Adjustment As Integer, EndYear As Integer,
StartYear As IntegerDim X_Axis_Array(1 To 100) As VariantDim SelectedStmt As StringDim X_Axis_ArrayEnd As IntegerTodays
[Code] ........
I've written this function to re-dimension an array based on the size of the range it is storing. Originally all my variables were simply declared as:
Code:
Dim XLRecOutput() as Variant
I then wrote a function which took the variable and the range as follows:
Code:
Function LoadRangeToArray(dataArray() As Variant, selectedRange As Range, Optional blnLoadData As Boolean = True)
With selectedRange
ReDim dataArray(1 To .Rows.Count, 1 To .Columns.Count)
End With
If blnLoadData Then dataArray = selectedRange
LoadRangeToArray = dataArray
End Function
To call the function, it's simply:
Code:
XLRecOutput = LoadRangeToArray(XLRecOutput, Range("XLRecOutput"))
Now I've created a class and set up Get/Let properties for the variables instead, but the above function fails with a Compile error on the call - 'Type mismatch: array or user-defined type expected' and I can't get my head around how to resolve it.
I found quite a few posts about this problem, but none of the answers was any use to me. I need to redimension a 2 dimensional array in a Sub. I deleted all the code that is not of interest:
View 3 Replies View RelatedCan I redim an array that is held within an array? I have (for example) 3 worksheets, and from each one I want to load 2 columns into an array. However I also want (I think) those 3 arrays to be contained within one array so that I can step through them easily. The code below will not run, but might better show what I am wanting;
View 2 Replies View Related