Assign Cell Value to array

Hello All!

I'm trying to write a code which will assign the value of a cell to an array...

Following is my code snippet:

Dim c As Variant
Dim aypartList() As Variant 'array of partnumbers
Dim ayCount As Integer

ayCount = 0

Do

c.Select
aypartList(ayCount) = c.Value 'Type mismatch error 13 shown in this line
' Im trying to assign the value of cell "c.value" to aypartList(0) etc
ayCount = ayCount + 1

Loop

ReDim Preserve aypartList(0 To ayCount) As Variant

MsgBox aypartList(ayCount)

I'd like to know where i went wrong...!!

Thanks a lot in advance!!

Nick's picture

does the selection contain

does the selection contain any errors ?

.. you can assign an array to a variable by this line of code:
myArray = range("A1:A10").Value

for example

I modified the line as

I modified the line as follows:

aypartList(ayCount) = Range("cnext").Value

It pops out an error saying " Runtime error : 1004 Method range of object Global failed"

Is there another way of assigning value of a cell to an array_name(index)variable?

Please suggest...!!

Thanks a ton for the quick reply!

Vishesh's picture

change

change to
aypartList(ayCount,1) = Range("cnext").Value

Also, Range("cnext") should refer to one cell only.