LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Dynamically declare and populate variables

I have a worksheet that lists database fields, corresponding excel variables
and the data type for each. I'd like to run through the list of variables
and declare each one with the appropriate data type. I've pasted the code
snippet below:

'Load the Variables into an array
ReDim DataVars(HowManyCols) As String
ReDim DataOffset(HowManyCols) As String

Dim Counter As Integer
Counter = 1

'Dimension data and column offset variables
For Each V In VarRange
DataVars(Counter) = V.Value
Select Case V.Offset(ColumnOffset:=1)
Case Is = "Long"
Dim DataVars(Counter) As Long
Case Is = "String"
Dim DataVars(Counter) As String
Case Is = "Date"
Dim DataVars(Counter) As Date
Else
Dim DataVars(Counter) As Variant
End Select

DataOffset(Counter) = V.Value & "_OFF"
Dim DataOffset(Counter) As Integer
Counter = Counter + 1
Next V

When it hits the Dim statement, the Complie error is: Constant expression
required.

Any help you can offer would be greatly appreciated.
 
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
Declare variables to a code? Pas Excel Discussion (Misc queries) 6 April 10th 10 01:14 PM
Declare Variables in Array Mike H. Excel Discussion (Misc queries) 2 March 11th 09 12:33 PM
Declare and Set Public variables jlclyde Excel Discussion (Misc queries) 2 January 28th 09 02:16 PM
How to efficiently declare variables Jeff Excel Discussion (Misc queries) 2 June 29th 06 01:56 PM
Best place to declare variables Taras Excel Programming 7 November 27th 03 04:34 PM


All times are GMT +1. The time now is 09:42 PM.

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"