+ Reply to Thread
Results 1 to 7 of 7

correctly 'wording' a for/next loop using a variable counter and variable filter

  1. #1
    Registered User
    Join Date
    07-11-2016
    Location
    America
    MS-Off Ver
    2010
    Posts
    10

    correctly 'wording' a for/next loop using a variable counter and variable filter

    Hello,

    I'm not sure any of this is correct.

    I want to copy the 4 cells[B:E] in every row that is > than my target date[J75], to a new range[K3:N60).

    Daterange1 is a user defined variable from another sheet.
    Countervalue1 is an automatic variable to limit the number of times the loop occurs.

    Please Login or Register  to view this content.
    Any assistance would be appreciated.

    Thanks.

    DBoyd

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: correctly 'wording' a for/next loop using a variable counter and variable filter

    What do you actually want to loop through?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    07-11-2016
    Location
    America
    MS-Off Ver
    2010
    Posts
    10

    Re: correctly 'wording' a for/next loop using a variable counter and variable filter

    Maybe I don't need to loop through anything.

    I want to copy all rows with a date > a customer-defined date, to a new location/table.


    Please Login or Register  to view this content.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: correctly 'wording' a for/next loop using a variable counter and variable filter

    What sheets are involved? ie which sheet is E3:E60 on and which sheet does Daterange1 come from

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: correctly 'wording' a for/next loop using a variable counter and variable filter

    The help file for the Range object https://msdn.microsoft.com/EN-US/lib.../ff838238.aspx includes sample code that uses the built in Advanced filter tool to copy data the meets a criteria (unique values in the example's case). I expect that, if you figure out how to formulate the "criteria range" criteria, the advanced filter could be used to extract the desired data from the table and enter it into another range.
    Last edited by MrShorty; 07-14-2016 at 06:01 PM. Reason: add link to help file
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  6. #6
    Registered User
    Join Date
    07-11-2016
    Location
    America
    MS-Off Ver
    2010
    Posts
    10

    Re: correctly 'wording' a for/next loop using a variable counter and variable filter

    Excellent. This might be part of my problem.
    I am working with two workbooks, so my cell designations might be wrong.

    Daterange1 originally comes from workbook2, but I have it copied to workbook1 sheet2 cell J75
    E3:E60 is in workbook1 sheet 2.

    I'm might be making this too complicated.
    If a row has a date after my daterange1, I want to copy some cells, from that row to a different row on a different sheet. (Or directly into workbook2, I don't care which.)
    Done.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: correctly 'wording' a for/next loop using a variable counter and variable filter

    Looping through a range is pretty straightforward.

    Here's one example.
    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] How to set a variable in combination with a looping x counter
    By herbie226 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-10-2016, 02:48 PM
  2. [SOLVED] VB Loop different variables and stop variable to find a new variable..
    By feroguz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-14-2014, 04:54 PM
  3. Require a counter with more than one variable
    By Runce in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-19-2014, 04:20 AM
  4. Adding a counter variable to code
    By nav505 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-14-2013, 08:28 PM
  5. Replies: 6
    Last Post: 12-21-2012, 08:03 AM
  6. Replies: 1
    Last Post: 10-27-2012, 02:54 AM
  7. [SOLVED] Counter variable in For Loop
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-08-2006, 02:00 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