+ Reply to Thread
Results 1 to 12 of 12

Skip loop if cells equal same values

  1. #1
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Skip loop if cells equal same values

    I currently have the code below that runs from row 4 in worksheet "Coupon" until it reaches the last last non-blank row.

    Please Login or Register  to view this content.
    I want to make a tweak to this so that it is more optimized, not doing unnecessary work any runs much more quickly. What I would like to do is to only run this part of the code

    Please Login or Register  to view this content.
    If the values in columns J and K are not equal to columns BB and BC. If they are then skip this loop and move on to the next row.

    Does this all make sense?
    Last edited by adam2308; 07-02-2012 at 09:39 AM.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Skip loop if cells equal same values

    Hi Adam2308,

    Maybe:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Re: Skip loop if cells equal same values

    Thank you xladept.

    Firstly, I changed
    Please Login or Register  to view this content.
    to all be on the same line as it was highlighted as red font and didn't seem to work this way. Let me know if I shouldn't have done this.

    I then copied your code over mine and I am getting a "compile error: Variable not defined" and it highlights "J" in the line of code
    Please Login or Register  to view this content.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Skip loop if cells equal same values

    Hi Adam 2308,

    It's Ok to have it on one line but remove the colon and End If.

  5. #5
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Re: Skip loop if cells equal same values

    Done that. So the line of code now reads
    Please Login or Register  to view this content.
    But still getting the same compile error message.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Skip loop if cells equal same values

    Have you put the GetNext procedure before the Next i?
    Last edited by xladept; 07-01-2012 at 04:10 PM.

  7. #7
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Re: Skip loop if cells equal same values

    Still getting the same compile error without dots in ".range"

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Skip loop if cells equal same values

    Please Login or Register  to view this content.
    Try this line.

  9. #9
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Re: Skip loop if cells equal same values

    ok, we have progress in that line of code now works but the code overall doesn't do what I was looking for.

    I have attached a workbook to try and show you more clearly. If you click CommandButton2 then it will run the code we are discussing. Now, in this example, the code we changed should mean that only the first match (Arseanl v Bolton) on the 'coupon' is process because all the other matches have the same values in columns J & K as BB & BC. However, all matches are processed and copied on to the csv files created. The csv files on this example should only contain the Arsenal v Bolton match.
    Attached Files Attached Files

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Skip loop if cells equal same values

    Hey Adam2308,

    I tested your workbook and our code but by just testing the J vs BB values there were no matches in your sample.

    BTW the .Range code works as well as the .Cells code on my machine - perhaps there was something else going on.

    Here's how I tested it:

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Re: Skip loop if cells equal same values

    Sorry, I gave you the wrong columns! It should have been H and I!!! Works perfectly now.

    Note to self - Don't work on projects with an hangover!

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Skip loop if cells equal same values

    Great, I'm glad to have helped.

+ 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