+ Reply to Thread
Results 1 to 4 of 4

'build' a variable from within a for/next loop

  1. #1
    Registered User
    Join Date
    07-26-2010
    Location
    NL
    MS-Off Ver
    Excel 2016
    Posts
    74

    'build' a variable from within a for/next loop

    Hello,

    I'm writing a vba script to change, remove, cleanup and enrich records in a certain file, this file is delevered once a week.
    I need to be sure that the file I use as input is always correct, otherwise my vba script will not run properly, therefore I check the columnheaders within the file.

    I could solve this with with successive if statemements but I would like to tackle this a little shorter and more systematically, that way I can use this script in other files too.

    I came up with the following code, the problem is that I would like to use the number in the for/next loop (k) inside another variable, so in the first loop, the variable k1 is addressed, in the second loop k1, etc. etc.

    Please Login or Register  to view this content.
    Is this possible at all? Please let me know.

    Best Regards,

    ABBOV

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: 'build' a variable from within a for/next loop

    You cannot do it like that, but you can do it like
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-26-2010
    Location
    NL
    MS-Off Ver
    Excel 2016
    Posts
    74

    Re: 'build' a variable from within a for/next loop

    Quote Originally Posted by Fluff13 View Post
    You cannot do it like that, but you can do it like
    Please Login or Register  to view this content.
    Thanks Fluff13, that did it!

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: 'build' a variable from within a for/next loop

    You're welcome & thanks for the feedback

+ 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. Build named variable dynamically
    By sumdumgai in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 08-16-2016, 09:09 AM
  2. Trying to build loop with conditional sums
    By Jeep_Mike in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2014, 10:21 AM
  3. [SOLVED] How can I build a Range, use it and remember it in a variable for later in a function?
    By Geek4eye in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-08-2012, 01:49 PM
  4. Why did an inner loop variable start overwriting the outer loop range suddenly?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2012, 03:24 PM
  5. Can I build variable names in a VBA loop?
    By barryleajo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-20-2010, 12:31 PM
  6. Replies: 0
    Last Post: 05-27-2010, 02:04 PM
  7. Macro - Series of formulas in a loop to build tables
    By kostas in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-09-2008, 05:38 AM

Tags for this Thread

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