+ Reply to Thread
Results 1 to 8 of 8

Function to step through an array only once per call.

  1. #1
    Registered User
    Join Date
    11-29-2018
    Location
    Sunny Cairns, QLD AUST
    MS-Off Ver
    2010
    Posts
    97

    Function to step through an array only once per call.

    Hi all.

    Not sure if this can be done or not but here goes.

    I have a variable in a macro that needs to be incremented from an array inside a For/Next loop. The For/Next loop steps through 30 times, once per chart update. I also need to update a variable from an array. The array contains a set of numbers relating to rows on worksheets.

    I am not sure how to go about doing this. I have the For/next loop working fine now but I can't get the variable to only update once per loop.

    Here is what I have so far. I have started to put the array inside a function, may or may not be the way to go.

    Please Login or Register  to view this content.
    Here is where it is called from.

    Please Login or Register  to view this content.
    Last edited by Pepe Le Mokko; 02-28-2020 at 03:27 AM. Reason: Moved to correct sub forum...

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Function to step through an array only once per call.

    As far as I can see this code would do nothing other than return an error.

    You have a For without a next
    You have not set SetRowNum to anything

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    11-29-2018
    Location
    Sunny Cairns, QLD AUST
    MS-Off Ver
    2010
    Posts
    97
    I realise the lack of next. I know if I put the next in it Will just loop and do nothing. I actually worked it out another way. I will post my code on Monday when I am back at work.
    Quote Originally Posted by mehmetcik View Post
    As far as I can see this code would do nothing other than return an error.

    You have a For without a next
    You have not set SetRowNum to anything

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    11-29-2018
    Location
    Sunny Cairns, QLD AUST
    MS-Off Ver
    2010
    Posts
    97

    Re: Function to step through an array only once per call.

    Here is what I have come up with that works....for now. I still want to do a few tweaks.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Function to step through an array only once per call.

    Quote Originally Posted by Dragondude View Post
    ... I have a variable in a macro that needs to be incremented from an array inside a For/Next loop. ...
    ? Which one variable is it ?

  6. #6
    Registered User
    Join Date
    11-29-2018
    Location
    Sunny Cairns, QLD AUST
    MS-Off Ver
    2010
    Posts
    97

    Re: Function to step through an array only once per call.

    Originally "b" was the for next loop and "d" needed to step through the array arr1 for each "b". I swapped them around and now it works a charm. It could possibly do with some cleaning up but my learning curve is very steep at the moment. I have managed to reduce about 4000 lines of code down to a couple of hundred. My brain now really hurts. I have attached the complete code below as is won't let me post the code..
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Function to step through an array only once per call.

    I am sure that there is an error in your functions.

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 03-01-2020 at 08:51 PM.

  8. #8
    Registered User
    Join Date
    11-29-2018
    Location
    Sunny Cairns, QLD AUST
    MS-Off Ver
    2010
    Posts
    97

    Re: Function to step through an array only once per call.

    Good pick up. I had it that way so I knew what I was trying to achieve. I knew it needed cleaning up. Its all a big learning process.

    Thank you

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Array function not returning array (or allowing step thru)
    By Mark43 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-20-2019, 11:04 PM
  2. [SOLVED] Ambiguous behaviour: Single step execution versus Call
    By Lloyd Blankfein in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-13-2019, 04:12 AM
  3. # vba array 2d every step 2 and step 3 $
    By daboho in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-25-2017, 01:53 PM
  4. My brain hurts - Help creating multi-step array/lookup
    By wallock in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 10-24-2014, 04:15 AM
  5. [SOLVED] Single-Step Array Formula
    By andrewc in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-11-2014, 11:51 PM
  6. Array as attribute in function call
    By Joakim N in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-19-2012, 10:57 AM
  7. One step further on formula to eliminate duplicate records in array.
    By harleypop in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-31-2009, 03:24 PM

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