+ Reply to Thread
Results 1 to 9 of 9

Loop with And

Hybrid View

  1. #1
    Registered User
    Join Date
    06-09-2012
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Loop with And

    Quote Originally Posted by Mordred View Post
    Hi Andy, I think it may be because your code doesn't know which sheet it is supposed to run this on. Try declaring the sheet name, it should be similar to the following but perhaps with a different sheet name:
    Dim ws1 As Worksheet
        Set ws1 = Worksheets("Sheet1")
    With the sheet declared, you can now specifically call the proper ranges like
    Do Until ws1.Range("F" & fircount).Value = cmdPassNum.Value And ws1.Range("H" & fircount).Value = ""
    fircount = fircount + 1
    Loop
    You should do that for all ranges, rows, columns, cells, and whatever else requires explicit sheet calls. Let me know how it goes.
    Thanks for the suggestion, unfortunately however, I have exactly the same debug message.

    Quote Originally Posted by Richard Buttrey View Post
    Hi,
    When it debugs what is the value of 'fircount' and cmdPassNum?

    What do cells F & H on the fircount row show? Are these errors?

    If this doesn't help you'll need to upload your workbook.
    The value of 'fircount' is 1048577 and the value of cmdPassNum is 1.

    The value in column F should be the same as the value in cmdPassNum and the value in column H should be blank.

    Many thanks,

    Andy

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Loop with And

    If 1048577 is indeed the value of fircount then that's one more than Excel 2007 has rows and will be the cause of your problem.

    You'll need to limit the loopcounter in some way - perhaps by detecting the last valid row.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ 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