PC Review


Reply
Thread Tools Rate Thread

Dynamic Array problem

 
 
Jean-Jerome Doucet via OfficeKB.com
Guest
Posts: n/a
 
      16th Jun 2005
Hi,

I want to put data in a dynamic Array with a looping. If I use a variable to
change the position in my vurtual dynamic array,it gives me an error saying I
am out of range. The solution I've found and tried in other posts is to redim
the array, but by doing so I loose all the other datas from the previous
positions (other than the actual position redimed). SO is there a way make my
dynamic array works?

Thanks!

JJD

Sub Age_moyenne_ponderee()

'Je déclare es tableaux et mes variables que j'aurai besoin pour
incrémenter.
Dim tabdynamique() As Double
Dim I As Long
Dim J As Variant
J = 0
Dim Z As Integer

' Age looping. Le principe est que la boucle effectue le calcul sur la ligne
la ligne si _
elle voit qu'elle n'est pas vide et change de ligne une fois la
suppression _
de la ligne effectuée.

For I = 12 To 65536

If Worksheets("Formulaire").Range("A" & I).Value <> "" Then

J = J + 1
ReDim tabdynamique(J)
tabdynamique(J) = (((Worksheets("Formulaire").Range("E" & I).Value)
/ (Worksheets("Formulaire").Range("R5").Value)) * (Worksheets("Formulaire").
Range("H" & I).Value))

Sheets("Formulaire").Range("AF" & I).Value = tabdynamique(J)
Else
Exit For
End If
Next I

End Sub

--
Message posted via http://www.officekb.com
 
Reply With Quote
 
 
 
 
Michael Bauer
Guest
Posts: n/a
 
      16th Jun 2005
Salut Jean,

calling Redim Preserve tabdynamique(J) preserves the previous array
elements.

Anyway, in your sample I´d go another way. It´s very expensive (in time)
to call Redim again and again. Instead you could dim the array once at
the beginning for the maximum size, count the needed space in J as you
do already, and trim the array once in the end.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook


"Jean-Jerome Doucet via OfficeKB.com" <(E-Mail Removed)> wrote
in message news:(E-Mail Removed)...
> Hi,
>
> I want to put data in a dynamic Array with a looping. If I use a

variable to
> change the position in my vurtual dynamic array,it gives me an error

saying I
> am out of range. The solution I've found and tried in other posts is

to redim
> the array, but by doing so I loose all the other datas from the

previous
> positions (other than the actual position redimed). SO is there a way

make my
> dynamic array works?
>
> Thanks!
>
> JJD
>
> Sub Age_moyenne_ponderee()
>
> 'Je déclare es tableaux et mes variables que j'aurai besoin pour
> incrémenter.
> Dim tabdynamique() As Double
> Dim I As Long
> Dim J As Variant
> J = 0
> Dim Z As Integer
>
> ' Age looping. Le principe est que la boucle effectue le calcul sur

la ligne
> la ligne si _
> elle voit qu'elle n'est pas vide et change de ligne une fois la
> suppression _
> de la ligne effectuée.
>
> For I = 12 To 65536
>
> If Worksheets("Formulaire").Range("A" & I).Value <> "" Then
>
> J = J + 1
> ReDim tabdynamique(J)
> tabdynamique(J) = (((Worksheets("Formulaire").Range("E" &

I).Value)
> / (Worksheets("Formulaire").Range("R5").Value)) *

(Worksheets("Formulaire").
> Range("H" & I).Value))
>
> Sheets("Formulaire").Range("AF" & I).Value =

tabdynamique(J)
> Else
> Exit For
> End If
> Next I
>
> End Sub
>
> --
> Message posted via http://www.officekb.com


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Dynamic Array Problem Bob Phillips Microsoft Excel Programming 0 17th Sep 2008 08:31 AM
Dynamic Array problem Werner Microsoft Excel Programming 6 17th Jun 2005 06:40 PM
Dynamic array problem Matt Jensen Microsoft Excel Programming 9 31st Dec 2004 10:05 AM
dynamic array of pointers vs dynamic array of objects lemonade Microsoft VC .NET 1 10th Dec 2003 08:31 PM
Problem with Dynamic Array Zahid Microsoft Dot NET Compact Framework 1 11th Jul 2003 12:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:13 PM.