Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Dim and Redim

Hi All,

I am interested in knowing why this is not working ....

dim arr() as integer

some code .....

redim preserve arr(20) as integer

If I use redim in the first line - redim arr() as integer then it works.

So in short my question is why redim doesn't work after dim on the same
array? It says it is supposed to work according to the excel help files.

thanx
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Dim and Redim

You do not want to specify "As Integer" on the redim statement...

dim arr() as integer

redim preserve arr(20)

--
HTH...

Jim Thomlinson


"Sean" wrote:

Hi All,

I am interested in knowing why this is not working ....

dim arr() as integer

some code .....

redim preserve arr(20) as integer

If I use redim in the first line - redim arr() as integer then it works.

So in short my question is why redim doesn't work after dim on the same
array? It says it is supposed to work according to the excel help files.

thanx

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Dim and Redim

Hi Jim,
I tried that and it still won't work.

this is the code...
Sub try()

Dim arr() As Integer
Dim first As Integer

Range("A1").Select
first = 1

Do While ActiveCell.Offset(first, 0).Value < ""
arr(first) = ActiveCell.Offset(first, 0).Value
first = first + 1
Loop

ReDim Preserve arr(100)
'Call sort(arr)
first = 1

Do While ActiveCell.Offset(first, 0).Value < ""
ActiveCell.Offset(first, 1).Value = arr(first)
first = first + 1
Loop

End Sub

It says application-defined or object-defined error.
thanx

"Jim Thomlinson" wrote:

You do not want to specify "As Integer" on the redim statement...

dim arr() as integer

redim preserve arr(20)

--
HTH...

Jim Thomlinson


"Sean" wrote:

Hi All,

I am interested in knowing why this is not working ....

dim arr() as integer

some code .....

redim preserve arr(20) as integer

If I use redim in the first line - redim arr() as integer then it works.

So in short my question is why redim doesn't work after dim on the same
array? It says it is supposed to work according to the excel help files.

thanx

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Dim and Redim

You can not use the array until you have initailized it to some number of
items. Also note that arrays start at zero (unless you change the base)

Sub try()

Dim arr() As Integer
Dim first As Integer

Range("A1").Select
first = 1

Do While ActiveCell.Offset(first, 0).Value < ""
ReDim Preserve arr(first - 1)
arr(first - 1) = ActiveCell.Offset(first, 0).Value
first = first + 1
Loop

'Call sort(arr)
first = 1

Do While ActiveCell.Offset(first, 0).Value < ""
ActiveCell.Offset(first, 1).Value = arr(first - 1)
first = first + 1
Loop

End Sub
--
HTH...

Jim Thomlinson


"Sean" wrote:

Hi Jim,
I tried that and it still won't work.

this is the code...
Sub try()

Dim arr() As Integer
Dim first As Integer

Range("A1").Select
first = 1

Do While ActiveCell.Offset(first, 0).Value < ""
arr(first) = ActiveCell.Offset(first, 0).Value
first = first + 1
Loop

ReDim Preserve arr(100)
'Call sort(arr)
first = 1

Do While ActiveCell.Offset(first, 0).Value < ""
ActiveCell.Offset(first, 1).Value = arr(first)
first = first + 1
Loop

End Sub

It says application-defined or object-defined error.
thanx

"Jim Thomlinson" wrote:

You do not want to specify "As Integer" on the redim statement...

dim arr() as integer

redim preserve arr(20)

--
HTH...

Jim Thomlinson


"Sean" wrote:

Hi All,

I am interested in knowing why this is not working ....

dim arr() as integer

some code .....

redim preserve arr(20) as integer

If I use redim in the first line - redim arr() as integer then it works.

So in short my question is why redim doesn't work after dim on the same
array? It says it is supposed to work according to the excel help files.

thanx

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Dim and Redim

I see... thatx a lot.

"Jim Thomlinson" wrote:

You can not use the array until you have initailized it to some number of
items. Also note that arrays start at zero (unless you change the base)

Sub try()

Dim arr() As Integer
Dim first As Integer

Range("A1").Select
first = 1

Do While ActiveCell.Offset(first, 0).Value < ""
ReDim Preserve arr(first - 1)
arr(first - 1) = ActiveCell.Offset(first, 0).Value
first = first + 1
Loop

'Call sort(arr)
first = 1

Do While ActiveCell.Offset(first, 0).Value < ""
ActiveCell.Offset(first, 1).Value = arr(first - 1)
first = first + 1
Loop

End Sub
--
HTH...

Jim Thomlinson


"Sean" wrote:

Hi Jim,
I tried that and it still won't work.

this is the code...
Sub try()

Dim arr() As Integer
Dim first As Integer

Range("A1").Select
first = 1

Do While ActiveCell.Offset(first, 0).Value < ""
arr(first) = ActiveCell.Offset(first, 0).Value
first = first + 1
Loop

ReDim Preserve arr(100)
'Call sort(arr)
first = 1

Do While ActiveCell.Offset(first, 0).Value < ""
ActiveCell.Offset(first, 1).Value = arr(first)
first = first + 1
Loop

End Sub

It says application-defined or object-defined error.
thanx

"Jim Thomlinson" wrote:

You do not want to specify "As Integer" on the redim statement...

dim arr() as integer

redim preserve arr(20)

--
HTH...

Jim Thomlinson


"Sean" wrote:

Hi All,

I am interested in knowing why this is not working ....

dim arr() as integer

some code .....

redim preserve arr(20) as integer

If I use redim in the first line - redim arr() as integer then it works.

So in short my question is why redim doesn't work after dim on the same
array? It says it is supposed to work according to the excel help files.

thanx



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
redim preserve [email protected][_2_] Excel Programming 3 December 15th 05 01:40 PM
Dim / Redim of an Array Fred[_17_] Excel Programming 4 June 28th 04 03:16 PM
ReDim Problem Casey[_4_] Excel Programming 4 January 7th 04 10:41 PM
ReDim an Array Art[_5_] Excel Programming 3 October 25th 03 03:30 PM
Redim MyArray Peter Pantus Excel Programming 2 September 27th 03 03:37 PM


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