Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Why does this produce an error?


Public Sub initialize()
Dim NumberOfColumns As Integer
NumberOfColumns = 13
Dim p(NumberOfColumns) As Integer


end Sub


Seems that Excel doesn't like using Variables to intialize arrays. How
should this be done?


--
zaphod2003
------------------------------------------------------------------------
zaphod2003's Profile: http://www.excelforum.com/member.php...o&userid=34362
View this thread: http://www.excelforum.com/showthread...hreadid=541455

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Why does this produce an error?

Hi
You need

Public Sub initialize()
Dim NumberOfColumns As Integer
Dim p( ) as integer
NumberOfColumns = 13
ReDim p(1 to NumberOfColumns)


end Sub

So you decare the array first with p( ) if you don't yet know the index
range. Then you must ReDim it once the index range is known.

regards
Paul

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default Why does this produce an error?

Hi,

And as the warning message says you can use a Const.

Public Sub initialize()
Const NumberOfColumns = 13
Dim p(NumberOfColumns) As Integer
End Sub

Or use the ReDim

Public Sub initialize()
Dim NumberOfColumns As Integer
NumberOfColumns = 13
ReDim p(NumberOfColumns) As Integer
End Sub

Cheers
Andy

zaphod2003 wrote:
Public Sub initialize()
Dim NumberOfColumns As Integer
NumberOfColumns = 13
Dim p(NumberOfColumns) As Integer


end Sub


Seems that Excel doesn't like using Variables to intialize arrays. How
should this be done?



--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Why does this produce an error?


Thanks for your help much appreciated


--
zaphod2003
------------------------------------------------------------------------
zaphod2003's Profile: http://www.excelforum.com/member.php...o&userid=34362
View this thread: http://www.excelforum.com/showthread...hreadid=541455

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
Subtraction that doesn't produce an error Andy Excel Discussion (Misc queries) 2 November 3rd 09 09:37 PM
new datasource produce no tables jenn Setting up and Configuration of Excel 1 May 14th 09 06:30 AM
Produce the most recent date Julie Excel Worksheet Functions 6 February 22nd 07 01:07 AM
produce a formulate to produce assigned seats for dinner DavidJoss Excel Worksheet Functions 0 October 4th 05 02:29 AM
How do I produce a pictogram in Excel stuka Charts and Charting in Excel 2 July 9th 05 12:31 AM


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