#1   Report Post  
Posted to microsoft.public.excel.programming
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)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Read data

Hi Edmund,

I look at your question and made this:

Public Sub CopyRange()
Dim lRowLoop As Long
Dim lRowMax As Long
Dim lColLoop As Long
Dim lColMax As Long

Dim sSource As Worksheet
Dim sTarget As Worksheet

Dim rStart As Range

Application.ScreenUpdating = False
Set sSource = Sheets("Sheet1")

Set sTarget = Sheets("Sheet2")
sTarget.Select
Set rStart = ActiveCell

sSource.Select

lRowMax = Selection.Rows.Count
lColMax = Selection.Columns.Count

For lRowLoop = 1 To lRowMax
For lColLoop = 1 To lColMax
rStart.Offset(lRowLoop - 1, lColLoop - 1).Value =
Selection.Cells(lRowLoop, lColLoop).Value
Next
Next

Application.ScreenUpdating = True
End Sub

This solution assumes that on your target sheet the cell for the
upperleft corner where the values must be placed is allreadye selected.

HTH,

Executor


Edmund wrote:
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 I'm trying to learn
here is using machine's 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 don't 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)


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read data in a cell? Matthew Excel Discussion (Misc queries) 1 January 13th 09 12:21 PM
Read data from a Row to a Column Ken G. Excel Discussion (Misc queries) 5 September 11th 08 02:01 PM
Truncating read-in data sweens319 Excel Programming 3 December 9th 05 10:21 PM
read serial data How can I Read Serial Data Excel Programming 4 June 8th 05 10:47 PM
How to read data from xls files? Tim[_30_] Excel Programming 1 November 7th 03 02:30 PM


All times are GMT +1. The time now is 12:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright 2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"