+ Reply to Thread
Results 1 to 7 of 7

i = 1 to 15

  1. #1
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    639

    i = 1 to 15

    I have tried this with the For i = 1 to 15 but it asks for a next which isn't relevant to what I am doing.

    How do I set "i" with a variable value?

    Example of what I am doing

    Please Login or Register  to view this content.
    CellRef value increases to 13 as a duplicate of this code

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: i = 1 to 15

    Every FOR requires a corresponding NEXT.
    The NEXT statement causes the code to increment your variable.

    Does that help?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: i = 1 to 15

    A suggestion for your code
    Care about the FOR and the IF statement

    Please Login or Register  to view this content.
    - Battle without fear gives no glory - Just try

  4. #4
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    639

    Re: i = 1 to 15

    That was just a sample of the code. See below for the full code, you will see there is no need for a next in the code I just want to have one line of code for CellRef rather than 13 lines so my question still stands

    How do I assign "i" with the values 1-13 without using "For/Next"

    Please Login or Register  to view this content.
    Last edited by Sc0tt1e; 12-03-2014 at 07:20 PM.

  5. #5
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: i = 1 to 15

    If you want to sequentially increment a variable there's no getting around using one of VBA's looping constructs:
    For/Next
    Do/While
    Do/Until
    For Each/Next

    Choose one and implement it.

  6. #6
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    639

    Re: i = 1 to 15

    I don't want to increment it I just want to say "If anything between CellRef 1-13 is greater than "" then MsgBox"", not loop through 1-13 and check all

  7. #7
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: i = 1 to 15

    If CellRefs 1-13 are a contiguous in a row or column, then you could use one of Excel's native functions within VBA.
    Something like:
    Please Login or Register  to view this content.
    Otherwise, you'd need to either test each individually or using one of the looping constructs.

+ 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