Results 1 to 9 of 9

VBA DoUntil Issues

Threaded View

  1. #1
    Registered User
    Join Date
    10-04-2012
    Location
    Texas
    MS-Off Ver
    Excel 2007/10
    Posts
    43

    VBA DoUntil Issues

    Hi all--

    having an issue with some VBA code. The main goal is to print the desired sheets based on the numbers entered. Ex. user enters 123, 456, and 789. This will open sheets of those names and print them out. I am trying to design it so that if they enter a number that doesn't have a corresponding workbook named after it, it will skip this one and go on to the next (and doesn't enter "Printed" in the cell next to it.). With my current code, if there is one incorrect number, it works fine. However, if there are two in a row, it stops there and doesn't continue even if there are legitimate numbers after.

    Please let me know if that makes sense, here is my code:


    Sub DailyPrints()
    
    Range("C2:C25").Select
    Selection.ClearContents
    
    Dim CellValue As String
    Dim n As Integer
    
    n = 2
    
    Application.ScreenUpdating = False
    
    Sheets("Daily Prints").Range("A" & n).Select
    
    Do Until IsEmpty(Range("A" & n))
    Application.DisplayAlerts = False
    
    CellValue = Sheets("Daily Prints").Range("A" & n).Value
    Workbooks.Open "Z:\5. Postponement\Pick to Cart\" & CellValue & ".xlsx"
    On Error GoTo 30
    
    Call Prints
    ActiveWindow.Close
    Range("A" & n).Offset(0, 2).Value = "Printed"
    
    30 n = n + 1
    Err.Clear
    Application.Goto (ActiveWorkbook.Sheets("Daily Prints").Range("A" & n))
    
    Loop
    GetOut:
    
    Application.DisplayAlerts = True
    
    End Sub
    Last edited by chicagoland8; 04-04-2013 at 02:30 PM. Reason: code tags

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