+ Reply to Thread
Results 1 to 9 of 9

Loop through an array

  1. #1
    Registered User
    Join Date
    07-28-2009
    Location
    Chicago, Il
    MS-Off Ver
    Excel 2007
    Posts
    67

    Loop through an array

    I am trying to setup a macro and to be honest I am lost on how to loop with an array

    I have a workbook that the macro opens then goes to a specific page then pastes information. now the issue is that i have to paste in a specific Cell depending on a varCellvalue

    so if the cell says
    10am then paste in cell A1
    2pm then paste in cell A19
    6pm then paste in cell A37
    10pm then paste in cell A55

    I figure i would have to use a loop but if there is a more simpler way please let me know

    Thanks
    Last edited by Ricardo9211; 11-12-2009 at 10:17 PM. Reason: SOLVED

  2. #2
    Forum Contributor
    Join Date
    02-14-2007
    Location
    Chester, England
    MS-Off Ver
    2010 & 2016
    Posts
    312

    Re: Loop through an array

    Hi Ricardo9211

    Is there a logic to the examples you have given and are they the only options?

    I stand to be corrected but if they are the only options then you could just do an "IF" in the code to paste to the correct area.

    Can you upload an example?

    Jim

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Loop through an array

    I would use a SELECT CASE technique when the possible values start to increase like this:

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    07-28-2009
    Location
    Chicago, Il
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Loop through an array

    I would love to use the case macro but when i am going to paste i am in a totally different workbook

    Please Login or Register  to view this content.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Loop through an array

    You don't need to do all that switching back and forth and selecting. Humans manipulate data that way, VBA can address objects directly and manipulate them without selecting them first.

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 11-12-2009 at 08:14 PM. Reason: Edited copy command

  6. #6
    Registered User
    Join Date
    07-28-2009
    Location
    Chicago, Il
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Loop through an array

    I see what your saying about not bouncing around but I think i have an issue with how i am inputing because i error out when it tries the
    Windows("CallVolumeMacro2.xls").Range("A1:K18").Copy

    I get an "object doesn't support this property or method" run-time error '438':

  7. #7
    Registered User
    Join Date
    07-28-2009
    Location
    Chicago, Il
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Loop through an array

    ok I got it to work i was till puttin in the varcellvalue.

    works great

    thanks alot
    Last edited by Ricardo9211; 11-12-2009 at 08:49 PM. Reason: Resolved

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Loop through an array

    This is really tough with no sample sheets to test on. Try this:
    Please Login or Register  to view this content.

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Loop through an array

    Ah, good stuff! If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].


    (Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1