+ Reply to Thread
Results 1 to 4 of 4

For Loop to check two cells in each row...

  1. #1
    Registered User
    Join Date
    03-28-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    For Loop to check two cells in each row...

    I am stuck since I am somewhat of a noob when it comes to VBA. Trying to advance beyond the noob.

    Fairly simple problem that I have half figured out.

    Basically, I need to look at two columns of numbers in a data sheet. If one or both of those columns in each row is greater than 500, then add that row to another sheet.

    My pseudo code would look like:

    Get last row.

    For loop starting with first row till end of data (last row)
    If row i cell C > 500 add entire row to sheet2

    Else if row i cell J > 500 add entire roww to sheet 2

    End if
    Go to next row


    I have something that will work with one column, but I need to check the second column if the first doesn't meet the criteria. If someone can point me in the right direction, I would much appreciate it. Ultimately I need to check 5 cells for each row...but if I can see how it is done for two...checking 5 should be easy.
    Please Login or Register  to view this content.
    Last edited by tekmann33; 09-28-2013 at 09:03 PM.

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: For Loop to check two cells in each row...

    Hi tekmann33,

    Try this from the tab containing the data:

    Please Login or Register  to view this content.
    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Registered User
    Join Date
    03-28-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: For Loop to check two cells in each row...

    Perfect!

    One question:
    What exactly is happening with the Else statement in the for loop?

    Is it looking for existing data, going to the end of that data and appending to that data?

    I will look it up...this is how I learn..but if I wanted to create a new sheet name and copy my results to it...what object method should I be looking at?

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: For Loop to check two cells in each row...

    What exactly is happening with the Else statement in the for loop?
    Depends on which statement you mean as I nested two statements. I assume it's the second which is simply finding which row in Sheet2 to use for the data being transfered.

    I will look it up...this is how I learn..but if I wanted to create a new sheet name and copy my results to it...what object method should I be looking at?
    You can use something like the wstMySheet variable below:

    Please Login or Register  to view this content.
    If you could mark this thread as solved it would be appreciated.

    Regards,

    Robert

+ 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 write loop to check for empty cells
    By JaydenK in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-22-2013, 09:17 AM
  2. How to check if two consecutive cells contain same prefix and switch on loop
    By hh92 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-09-2013, 06:36 AM
  3. While loop to check value in adajacent cells and then place it depending on value
    By joshnathan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-16-2012, 10:35 AM
  4. Loop to check condition of cells
    By keith156 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-29-2011, 10:44 AM
  5. how to do a loop and check cells
    By philmetz in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-11-2009, 06:37 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