Extracting values from cells (in one column) and putting in an arr

V

Varun

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.
 
P

Per Jessen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top