View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Per Jessen[_2_] Per Jessen[_2_] is offline
external usenet poster
 
Posts: 703
Default Extracting values from cells (in one column) and putting in anarr

Hi

Try this:

Sub ValToArr()
Dim MyArray
Set StartCell = Range("A14")
Set EndCell = Range("A" & Rows.Count).End(xlUp)
rowCount = EndCell.Row - StartCell.Row
ReDim MyArray(rowCount / 2 + 1)
For r = StartCell.Row To EndCell.Row Step 2
i = i + 1
MyArray(i) = Cells(r, "A").Value
Next
End Sub

Regards,
Per


On 26 Jan., 22:55, Varun wrote:
Hi All,

VBA newbie here. *I haven't done my homework fully yet so I am not asking
for the complete answer, rather some help to jump start my thinking process.

What I need to do is come up with a code that will read the value (it's an
integer) from cells in one column i.e. column A.

The start value is in cell A14 and then it appears in every 2nd consecutive
cell down from A14. *For example, A14 contains 1, then A16 contains 2, A18
contains 3 and so on...so I'd like to read all the values in an array, then
stop when the cells are empty.

How can I get around this? *Thanks.