Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Declaring variables programmatically

Hello,
In some procedure, I use an array lilke my Array =
(100,160,200,280,290,.........560), some 50 numbers in all.
Furthere down the sub I need to create Ranges like R100, R160, R200,
R280.....R560, based on the numbers in the array.

Is there any smart way to do this without having to write 50 range
declarations and then 50 Set-commands manually?
Thank you very much for any help!
Herman
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 420
Default Declaring variables programmatically

You don't have to use individual variables for the range names. You could use a
second array:

Option Explicit
Sub testme()

Dim myArr As Variant 'array of longs
Dim myRanges() As Range 'array of ranges
Dim iCtr As Long 'looping variables

myArr = Array(100, 160, 200) 'just 3

'make myRanges the same size as myArr
ReDim myRanges(LBound(myArr) To UBound(myArr))

'I'm not sure what you're doing here, though:
For iCtr = LBound(myRanges) To UBound(myRanges)
'Set myRanges(iCtr) = somerangebasedonmyarr
'maybe...
Set myRanges(iCtr) = Worksheets("Sheet1").Range("R" & myArr(iCtr))
Next iCtr

End Sub


=========
Another option would be to look at the Type statement in VBA's help:

Option Explicit
Type myType
myNum As Long
myRng As Range
End Type
Sub testme()

Dim myArr(1 To 3) As myType
Dim iCtr As Long

myArr(1).myNum = 100
myArr(2).myNum = 160
myArr(3).myNum = 200

For iCtr = LBound(myArr) To UBound(myArr)
'still not sure what you're doing here
Set myArr(iCtr).myRng _
= Worksheets("Sheet1").Range("R" & myArr(iCtr).myNum)
Next iCtr

End Sub



On 12/13/2010 07:00, Herman wrote:
Hello,
In some procedure, I use an array lilke my Array =
(100,160,200,280,290,.........560), some 50 numbers in all.
Furthere down the sub I need to create Ranges like R100, R160, R200,
R280.....R560, based on the numbers in the array.

Is there any smart way to do this without having to write 50 range
declarations and then 50 Set-commands manually?
Thank you very much for any help!
Herman


--
Dave Peterson
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
Declaring Variables BlairH Excel Programming 3 June 4th 10 03:04 PM
Declaring variables freekrill Excel Discussion (Misc queries) 0 July 18th 06 06:15 PM
Declaring variables Mike Excel Programming 4 November 28th 05 07:05 PM
Declaring Variables Robert[_16_] Excel Programming 2 November 20th 03 04:16 PM
Declaring Variables chris brunt Excel Programming 2 August 4th 03 02:02 PM


All times are GMT +1. The time now is 06:08 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"