Thread: Read data
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Edmund Edmund is offline
external usenet poster
 
Posts: 62
Default Read data

VBA rookie here.

How do I get VBA to €śread€ť data of a selected range? The range is dynamic
(which can contain any number of rows or columns) & is determined by user
selection.

I heard that codes can run faster without selecting range. So instead of
having VBA to keep flipping between the source sheet (copy) & target
sheet(paste), I plan to get Excel to €śmemorize€ť the content of each row &
column, then returning it on the target sheet in one go.

I know I can do this via copy & paste method but what Im trying to learn
here is using machines memory to read rows & columns.

I got the below method from a book & changed it a little. But this example
only generates reads a single column. I just dont know how to make it read
from a dynamic range of selected cells with uncertain number of rows & column.

Pls show me. Thank you.

Private Sub Testing_ReadData ()
Dim MyArray() As Double
RowCount = Selection.Rows.Count
ReDim MyArray(RowCount)
For r = 1 To RowCount
MyArray(r) = Selection.Cells(r, 1)
Next
For Each n In MyArray
Debug.Print n
Next n
End Sub

--
Edmund
(Using Excel XP)