+ Reply to Thread
Results 1 to 4 of 4

Using For Loop to Select non-contiguous rows VBA

  1. #1
    Registered User
    Join Date
    08-03-2016
    Location
    Harrisonburg, VA
    MS-Off Ver
    2013
    Posts
    4

    Using For Loop to Select non-contiguous rows VBA

    Hi,
    I'm trying to write VBA code which will generate multiple graphs for me. I need to code to select two rows (one is constant, the other is progressing...ie. Range(A2:Z2,(A(i):Z(i)))

    I'm getting stuck with this line.

    Sub Test()
    Dim i As Integer
    NumRows = Range("B3", Range("B3").End(xlDown)).Rows.Count
    For i = 3 To NumRows
    Range(Cells(i, 2), (Cells(i, 2).End(x1ToRight)).Select <------Error
    *****Code to generate Chart ****
    Next i

    I want to select (3,2) to the last value in row(3) then (4,2) to last value in row(4)...etc along with the header row(A2:Z2) then create a chart, Where Z2 is the last value in that header row.

    Any idea how to create this for loop?

  2. #2
    Forum Contributor
    Join Date
    04-24-2012
    Location
    Karlstad, Sweden
    MS-Off Ver
    Excel 2016
    Posts
    221

    Re: Using For Loop to Select non-contiguous rows VBA

    The Error row is because you have speeled wrong to x1ToRight. You have written a '1' instead of "l". Should be xlToRight.
    1. Reply to thread and inform if suggestion was helpful or not
    2. Click on the star (=Add Reputation) if you think someone helped you
    3. Mark [SOLVED] to this thread if solution was found. (On Menu "Thread Tools" > "Mark this thread as solved")

  3. #3
    Registered User
    Join Date
    08-03-2016
    Location
    Harrisonburg, VA
    MS-Off Ver
    2013
    Posts
    4

    Re: Using For Loop to Select non-contiguous rows VBA

    yea, that was a brainfart on my part. Thanks

  4. #4
    Registered User
    Join Date
    08-03-2016
    Location
    Harrisonburg, VA
    MS-Off Ver
    2013
    Posts
    4

    Re: Using For Loop to Select non-contiguous rows VBA

    One more thing...Now that I got that working, as it loops through the code it selects all rows between and not just the two individual rows. So it progresses from 2 row selection to 3 row selection etc.

    Please Login or Register  to view this content.

+ 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] Loop thru non-contiguous selection of cells
    By btmtdk in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-18-2014, 05:52 PM
  2. Loop through rows with VBA and select an excel output file with selectable dates
    By craigsmack in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-09-2014, 05:52 PM
  3. Select Non Contiguous dynamic range
    By kevinkusman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-13-2013, 03:20 AM
  4. Select & copy non-contiguous range
    By SunRise in forum Excel General
    Replies: 0
    Last Post: 01-08-2013, 05:56 PM
  5. [SOLVED] How to delete multiple contiguous (and/or) non-contiguous rows, in an excel table
    By jimmalk in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-03-2012, 05:48 AM
  6. Replies: 2
    Last Post: 11-04-2012, 12:18 AM
  7. How to select a range of non-contiguous rows
    By rgans in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-04-2005, 02:54 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