vba: what does ReDim Preserve do and simple array question
Posted
by every_answer_gets_a_point
on Stack Overflow
See other posts from Stack Overflow
or by every_answer_gets_a_point
Published on 2010-05-26T19:15:04Z
Indexed on
2010/05/26
19:21 UTC
Read the original article
Hit count: 219
i am looking at someone else's vba excel code. they are doing ReDim Preserve dataMatrix(7, i)
in both loops. what does this do?
also, it seems like the second loop just overwrites the data in the first, loop, is that correct?
Dim dataMatrix() As String
Worksheets.Item("ETS").Select
Do While Trim(Cells(r, 1)) <> ""
Debug.Print "The line: ", Trim(Cells(r, 1)), r
r = r + 1
dataMatrix(1, i) = Trim(Cells(r, 1)) ''file name
dataMatrix(2, i) = Trim(Cells(r, 2)) ''sample type
dataMatrix(3, i) = Trim(Cells(r, 3)) ''sample name
dataMatrix(4, i) = "ETS" ''
dataMatrix(5, i) = Trim(Cells(r, 5)) ''Response
dataMatrix(6, i) = Trim(Cells(r, 6)) ''ISTD Response
dataMatrix(7, i) = Trim(Cells(r, 10)) ''Calculated Conc
i = i + 1
ReDim Preserve dataMatrix(7, i)
Loop
r = 5
Worksheets.Item("ETG").Select
Do While Trim(Cells(r, 1)) <> ""
Debug.Print "The line: ", Trim(Cells(r, 1)), r
r = r + 1
dataMatrix(1, i) = Trim(Cells(r, 1)) ''file name
dataMatrix(2, i) = Trim(Cells(r, 2)) ''sample type
dataMatrix(3, i) = Trim(Cells(r, 3)) ''sample name
dataMatrix(4, i) = "ETG"
dataMatrix(5, i) = Trim(Cells(r, 5)) ''Response
dataMatrix(6, i) = Trim(Cells(r, 6)) ''ISTD Response
dataMatrix(7, i) = Trim(Cells(r, 10)) ''Calculated Conc
i = i + 1
ReDim Preserve dataMatrix(7, i)
Loop
© Stack Overflow or respective owner