+ Reply to Thread
Results 1 to 6 of 6

Run time Error 1004 in my Do While loop

  1. #1
    Registered User
    Join Date
    02-16-2013
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    9

    Run time Error 1004 in my Do While loop

    I am getting this to work but it will create the worksheet then give me the Error 1004. trying to figure out what I have wrong in this. I am going to want to run this and place a few other name sets that will create a new sheet if found

    Sub Do_While_loop()
    Dim Fail As String
    Fail = "Failure"
    r = 1
    Do Until Cells(r, 1) = ""
    Do Until r = Fail
    r = r + 1
    If Cells(r, 1) = Fail Then
    Sheets.Add.Name = "Failure"
    Sheets("Sheet1").Activate
    Exit Do
    End If
    Loop
    Loop


    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    818

    Re: Run time Error 1004 in my Do While loop

    You can't add a sheet with the same name twice.

    Maybe is this a solution.

    Please Login or Register  to view this content.
    Ps. Create from cell A1 a cell that you will never use, f.e. XFD1
    Last edited by HSV; 02-18-2013 at 08:00 PM. Reason: Ps
    Kind regards, Harry.

  3. #3
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Run time Error 1004 in my Do While loop

    How can r = Fail?

    r should be a number (long preferably to allow for Excel 2010's larger sheet sizes) so I'm missing something.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  4. #4
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    818

    Re: Run time Error 1004 in my Do While loop

    Nothing is missing, there is too much @abousetta

    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Run time Error 1004 in my Do While loop

    Hi,

    I should have noted that I was referring to the OP's original post. I thought there was something I was not understanding in the logic.

    abousetta

  6. #6
    Registered User
    Join Date
    02-16-2013
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Run time Error 1004 in my Do While loop

    Thanks.

    I guess what I am trying to do is I need a do until loop. Trying to run through column A where there will be multiple data strings of different variety but will have duplicates etc. I want to find the instance of one, stop the do loop and create a new sheet. I need it to return to the loop to check for the other types I specify.

    They are all string type elements. I am doing this on the fly so any help and guidance on building this is helpful!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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