Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Creating an Array from a Range using Offset

I am trying to create an Array from a Range of data in a spreadsheet. I am
able to do this successfully when I explicitly define the range, but I am
having touble doing it using a variable and the Offset command.

The following code works fine:

Sub RangeToArray()
Dim MyArray as Variant
MyArray = Sheets(1).Range("A1:B5")
End Sub

What I would like to do is something like this:

Sub RangeToArray()
Dim MyArray as Variant
Dim NumRows as Long
Dim NumCols as Long

NumRows = 5
NumCols = 2

MyArray = Sheets(1).Range("A1:(A1(offset(NumRows,NumCols)"))

End Sub

I just can't seem to get the syntax correct. I sure would appreciate any
help from the group.

Frank Hayes



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Creating an Array from a Range using Offset

MyArray = Sheets(10).Range("A1:" & Range("A1").Offset(numRows, _
numCols).Address)

Alan Beban

Frank & Pam Hayes wrote:
I am trying to create an Array from a Range of data in a spreadsheet. I am
able to do this successfully when I explicitly define the range, but I am
having touble doing it using a variable and the Offset command.

The following code works fine:

Sub RangeToArray()
Dim MyArray as Variant
MyArray = Sheets(1).Range("A1:B5")
End Sub

What I would like to do is something like this:

Sub RangeToArray()
Dim MyArray as Variant
Dim NumRows as Long
Dim NumCols as Long

NumRows = 5
NumCols = 2

MyArray = Sheets(1).Range("A1:(A1(offset(NumRows,NumCols)"))

End Sub

I just can't seem to get the syntax correct. I sure would appreciate any
help from the group.

Frank Hayes



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Creating an Array from a Range using Offset

Alan ... that worked perfectly. Thanks for the help.

Frank

"Alan Beban" wrote in message
...
MyArray = Sheets(10).Range("A1:" & Range("A1").Offset(numRows, _
numCols).Address)

Alan Beban

Frank & Pam Hayes wrote:
I am trying to create an Array from a Range of data in a spreadsheet. I

am
able to do this successfully when I explicitly define the range, but I

am
having touble doing it using a variable and the Offset command.

The following code works fine:

Sub RangeToArray()
Dim MyArray as Variant
MyArray = Sheets(1).Range("A1:B5")
End Sub

What I would like to do is something like this:

Sub RangeToArray()
Dim MyArray as Variant
Dim NumRows as Long
Dim NumCols as Long

NumRows = 5
NumCols = 2

MyArray =

Sheets(1).Range("A1:(A1(offset(NumRows,NumCols)"))

End Sub

I just can't seem to get the syntax correct. I sure would appreciate

any
help from the group.

Frank Hayes





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Creating an Array from a Range using Offset

Another possibility:

Dim MyArray as Variant
Dim NumRows as Long
Dim NumCols as Long

NumRows = 5
NumCols = 2

MyArray = Sheets(10).Range("A1").Resize(numRows, _
numCols)).Value

--
Regards,
Tom Ogilvy

"Alan Beban" wrote in message
...
MyArray = Sheets(10).Range("A1:" & Range("A1").Offset(numRows, _
numCols).Address)

Alan Beban

Frank & Pam Hayes wrote:
I am trying to create an Array from a Range of data in a spreadsheet. I

am
able to do this successfully when I explicitly define the range, but I

am
having touble doing it using a variable and the Offset command.

The following code works fine:

Sub RangeToArray()
Dim MyArray as Variant
MyArray = Sheets(1).Range("A1:B5")
End Sub

What I would like to do is something like this:

Sub RangeToArray()
Dim MyArray as Variant
Dim NumRows as Long
Dim NumCols as Long

NumRows = 5
NumCols = 2

MyArray =

Sheets(1).Range("A1:(A1(offset(NumRows,NumCols)"))

End Sub

I just can't seem to get the syntax correct. I sure would appreciate

any
help from the group.

Frank Hayes





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
Use of Offset function in array formula scabHead Excel Worksheet Functions 4 December 23rd 06 01:16 AM
Array Offset Function maperalia Excel Worksheet Functions 2 January 25th 06 07:20 PM
creating columns with data from offset rows Scott Kelley Excel Discussion (Misc queries) 2 November 14th 05 02:15 AM
using offset with array formulas QuantumPion Excel Worksheet Functions 1 June 7th 05 07:54 PM
OFFSET and array formulae Wazooli Excel Discussion (Misc queries) 3 January 20th 05 12:09 AM


All times are GMT +1. The time now is 10:14 PM.

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

About Us

"It's about Microsoft Excel"