+ Reply to Thread
Results 1 to 3 of 3

Newbie Question: Repeat Operations on Named Ranges - Can I loop this macro for efficiency?

  1. #1
    Registered User
    Join Date
    10-17-2013
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    5

    Question Newbie Question: Repeat Operations on Named Ranges - Can I loop this macro for efficiency?

    Hi all -

    I'm new to the Forum (This is my first post) and a relative beginner to programming in VBA. Please forgive the way I posted my code below, I couldn't figure out how to get it properly indented into the scrolling box (advice on that is also welcome!)

    I have a procedure that repeats 18 times based on a series of named ranges, and am trying to figure out how to loop the procedure to work for each range name in sequence and then increment, rather than paste the procedure 18 times (Which is what I have now).

    All of the resources I have consulted seem to give examples of looping through either a single range or all ranges on a worksheet. In this case I want to give the names of my ranges at the top of the Sub, then have the VBA code loop through only those ranges and perform the procedure. Is this even possible?

    The procedure asks the user how many rows to add to the range (in this case the range is named "_2530_kp1"), then it adds the number of rows selected and re-numbers them for visual clarity (in this case the range the numbers are added into is named "_2530_kps_count".

    ----------------------------------------------------------------------------------

    Please Login or Register  to view this content.
    Moderator Note:

    Pls use code tags around your code next time as per forum rules.
    Last edited by Fotis1991; 10-18-2013 at 08:38 AM.

  2. #2
    Registered User
    Join Date
    10-17-2013
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Newbie Question: Repeat Operations on Named Ranges - Can I loop this macro for efficie

    Thanks for the tip. I now see how to add code tags and will do so in all future posts.

  3. #3
    Registered User
    Join Date
    10-17-2013
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Newbie Question: Repeat Operations on Named Ranges - Can I loop this macro for efficie

    I solved this myself. First I declared a variant to serve as placeholder for an Array containing all of the Range names. Then, I inserted "v" (name of the variant) in place of the Range names during the repeating procedure. Worked flawlessly the first time and repeatedly after.

    I have to indirectly thank everyone here because I was able to solve it by reviewing Threads that each addressed part of my issue, then methodically wrote a For..Next loop which ran the process on each named range in succession. It's faster than my old code too. This Forum is a fantastic resource.

+ 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. [SOLVED] VBA Efficiency Question - better to call a private sub or repeat same code?
    By jellyjen17 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-10-2012, 12:29 PM
  2. Replies: 4
    Last Post: 07-21-2010, 10:24 AM
  3. Newbie repeat question
    By Patrick in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-16-2006, 06:10 PM
  4. [SOLVED] Vb ranges - Newbie question
    By MarkI in forum Excel General
    Replies: 3
    Last Post: 07-27-2006, 11:55 AM
  5. named ranges in a For Loop
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-22-2005, 11:10 AM

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