Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Creating sequential variables on the fly

I'm working on a spreadsheet where I need to find out how many entries I'll
need, then create sequentially-named variables for each of them in a VBA
subroutine.

(For example, I may need 0-6 variables. If I find out I need 3 variables,
then VariableCount = 3 and I'll want to name the variables Variable1,
Variable2 and Variable3.) This means that I want to Dim the variables then
fill them in. I feel comfortable with figuring out how to do that part...my
question is much simpler.

What is the syntax for appending a variable value onto the end of a variable
name to create a sequence of variables? I've tried a number of things, and
none have worked. I'm probably missing something basic yet again.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Creating sequential variables on the fly

Your best bet is to create a class module, and store instances of
that class in a Collection object.

Dim C As Class1
Dim Coll As New Collection
For N = 1 To NumVariables
Set C = New Class1
Coll.Add C
Next N

The class module can be as simple as

Public X As Integer


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"ForestRamsey" wrote in
message
...
I'm working on a spreadsheet where I need to find out how many
entries I'll
need, then create sequentially-named variables for each of them
in a VBA
subroutine.

(For example, I may need 0-6 variables. If I find out I need 3
variables,
then VariableCount = 3 and I'll want to name the variables
Variable1,
Variable2 and Variable3.) This means that I want to Dim the
variables then
fill them in. I feel comfortable with figuring out how to do
that part...my
question is much simpler.

What is the syntax for appending a variable value onto the end
of a variable
name to create a sequence of variables? I've tried a number of
things, and
none have worked. I'm probably missing something basic yet
again.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Creating sequential variables on the fly

Thanks for the response. It looks like I have a whole new area to learn in
VBA. I can see what tomorrow's reading will be.

Thanks again!

- Forest

"Chip Pearson" wrote:

Your best bet is to create a class module, and store instances of
that class in a Collection object.

Dim C As Class1
Dim Coll As New Collection
For N = 1 To NumVariables
Set C = New Class1
Coll.Add C
Next N

The class module can be as simple as

Public X As Integer


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"ForestRamsey" wrote in
message
...
I'm working on a spreadsheet where I need to find out how many
entries I'll
need, then create sequentially-named variables for each of them
in a VBA
subroutine.

(For example, I may need 0-6 variables. If I find out I need 3
variables,
then VariableCount = 3 and I'll want to name the variables
Variable1,
Variable2 and Variable3.) This means that I want to Dim the
variables then
fill them in. I feel comfortable with figuring out how to do
that part...my
question is much simpler.

What is the syntax for appending a variable value onto the end
of a variable
name to create a sequence of variables? I've tried a number of
things, and
none have worked. I'm probably missing something basic yet
again.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Creating sequential variables on the fly

Forest,
Are you asking about Arrays ?

Dim MyVar( ) As String 'Or whatever data type you want to use
ReDim MyVar(2)
MyVar(0)="Variable0" 'Or whatever value you want to store
'...etc
Above assumes you are working with "normal" array bounds and have not set
"Option Base 1".
So you would get 3 elements to array.

NickHK

"ForestRamsey" wrote in message
...
I'm working on a spreadsheet where I need to find out how many entries

I'll
need, then create sequentially-named variables for each of them in a VBA
subroutine.

(For example, I may need 0-6 variables. If I find out I need 3 variables,
then VariableCount = 3 and I'll want to name the variables Variable1,
Variable2 and Variable3.) This means that I want to Dim the variables

then
fill them in. I feel comfortable with figuring out how to do that

part...my
question is much simpler.

What is the syntax for appending a variable value onto the end of a

variable
name to create a sequence of variables? I've tried a number of things,

and
none have worked. I'm probably missing something basic yet again.



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
Creating sequential text string of fixed length dhstein Excel Discussion (Misc queries) 7 December 10th 08 03:52 AM
creating formulas for sequential numbers in excel tacks Excel Worksheet Functions 4 June 12th 08 05:08 AM
Creating part # tags using sequential numbering. Andrew M. Excel Discussion (Misc queries) 2 November 28th 06 08:04 PM
Creating a list in sequential order Mark Jackson Excel Worksheet Functions 6 November 7th 05 11:08 PM
Creating Sequential Numbering Macro for an Quotation template steewwy Excel Programming 2 May 16th 05 06:23 PM


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