Results 1 to 11 of 11

Thread: writing an array into a range

  1. #1

    Thread Starter
    Registered User jkw119's Avatar
    Join Date
    Oct 2001
    Location
    Pittsburgh
    Posts
    256

    writing an array into a range

    My program runs really slow. And I was wondering if it is because I use like 500 statements like this

    For i = 1 To 10000
    X2.Worksheets(1).Cells(y, 7) = MagneticDrag4(x)
    x = x + 1
    y = y + 1
    Next i

    Is there a better way to write the entire array into a column?

    Thanks,


    JEFF

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Well one thing that will speed it up a little ;

    VB Code:
    1. For i = 1 To 10000
    2.     'put code here
    3. Next

    See there's no index reference after the word Next.
    That should speed up the loop.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    what is ur code trying to achieve?

    w00t 4000 posts !

  4. #4
    Addicted Member Supester's Avatar
    Join Date
    Nov 2001
    Location
    The Netherlands
    Posts
    220
    Just out of curiousity when/where/how do you fill your array?

  5. #5
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Originally posted by Supester
    Just out of curiousity when/where/how do you fill your array?
    a cut and paste job?

    http://www.vbforums.com/showthread.p...hreadid=127118



    why did you do that?

  6. #6
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    actually, he doesn't even fill an array, so how is this relevant

    it seems as though he is not using an array :rolleys:

  7. #7
    Addicted Member Supester's Avatar
    Join Date
    Nov 2001
    Location
    The Netherlands
    Posts
    220
    da_sil....whatever, you got your 3000/4000 mail-count...cut the crap....start reply-ing to answers instead of some corny remark.....look at the thread again, I already posted that it was a in the wrong thread

  8. #8

    Thread Starter
    Registered User jkw119's Avatar
    Join Date
    Oct 2001
    Location
    Pittsburgh
    Posts
    256
    MagneticDrag4 is an array with about 10000 data points.

    Like MagneticDrag4(1) = 4.5 etc. ......MagneticDrag4(10000) = 0

    The problem is I am writing that array to an excel worksheets to graph it. so currently, I am writing the array, one data point at a time in a loop. And because I have 100 arrays, it takes like 15 minutes to run. I was wondering if there was a way to somehow just say, take the array and fill into the excel column.

    Thanks,

    JEFF

  9. #9
    Addicted Member Supester's Avatar
    Join Date
    Nov 2001
    Location
    The Netherlands
    Posts
    220
    Here's my idea, don't know whether it is faster, but you never know...

    there is a function in word to get a table as a text and you can copy/paste tables...

    you can try:
    - send the array as a string to word
    - let Word convert the text to a table
    - copy and paste the table to excel

    maybe this is faster?

    Have fun trying...if you are going to try it

  10. #10
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Originally posted by Supester
    da_sil....whatever, you got your 3000/4000 mail-count...cut the crap....start reply-ing to answers instead of some corny remark.....look at the thread again, I already posted that it was a in the wrong thread
    i do reply to threads, that's why i have a high post count

    i am allowed to post some garbage ones ocassionally too

    search thru enough of my posts and you'll find most of them help the person

  11. #11
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819
    Originally posted by jkw119
    MagneticDrag4 is an array with about 10000 data points.

    Like MagneticDrag4(1) = 4.5 etc. ......MagneticDrag4(10000) = 0

    The problem is I am writing that array to an excel worksheets to graph it. so currently, I am writing the array, one data point at a time in a loop. And because I have 100 arrays, it takes like 15 minutes to run. I was wondering if there was a way to somehow just say, take the array and fill into the excel column.

    Thanks,

    JEFF
    Can you put the data into a recordset instead of an array? If you can then you'll be able to lump it all into Excel in one go:
    VB Code:
    1. ActiveCell.CopyFromRecordset rstRecordsetName
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width