+ Reply to Thread
Results 1 to 5 of 5

How to make a Loop

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-04-2017
    Location
    Phillipines
    MS-Off Ver
    2016
    Posts
    169

    How to make a Loop

    Hi all?

    How to make a Loop for Print?

    Private Sub cmdReturn_Click()
    Dim ws As Worksheet
    Dim mybox As Variant
    
    mybox = InputBox("How many copies?")
    If mybox = "" Then
       MsgBox ("No number of copies")
       Else
       With Sheets("MrrPrint")
        '.PrintPreview
            .PrintOut Copies:=mybox
        End With
    
    
    s = MsgBox("Do You want to Exit?", vbYesNo, Question) '  If NO it will return to start  printing msgbox show  ("Mybox=Inputbox(How many copies?") will show again
    If s = vbYes Then
    'delete all
    With ws
          'Union(.Range("B13:O17"), .Range("C16:C17"), .Range("K16:K17"), .Range("O16:O17"), .Range("A24:Q40"), .Range("M48:m50")) = vbNullString 'Not working
        Range("B13:O17") = ""
       Range("C16:C17") = ""
       Range("K16:K17") = ""
        Range("O16:O17") = ""
        Range("A24:Q40") = ""
        Range("M48:m50") = vbNullString
    'Range (B13:
        End With
    end Sub
    Last edited by Chandria; 04-08-2019 at 07:46 AM. Reason: add. info

  2. #2
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: How to make a Loop

    Your request is a bit vague, does this do what you want?
    Private Sub cmdReturn_Click()
    Dim TimeToQuit As Long
    
    While TimeToQuit <> vbYes
        If InputBox("How many copies?") = "" Then
            MsgBox ("No number of copies")
        Else
            With Sheets("MrrPrint")
                '.PrintPreview
                .PrintOut Copies:=mybox
            End With
            TimeToQuit = MsgBox("Do You want to Exit?", vbYesNo, Question) ' Always Show print not click "YES"
        End If
    Wend
    'delete all
        Range("B13:O17,C16:C17,K16:K17,O16:O17,A24:Q40,M48:m50").ClearContents
    End Sub

  3. #3
    Forum Contributor
    Join Date
    07-04-2017
    Location
    Phillipines
    MS-Off Ver
    2016
    Posts
    169

    Re: How to make a Loop

    Dear jason.b75

    Here is the error
    [img]619155[/img]
    Attached Images Attached Images
    Last edited by Chandria; 04-08-2019 at 07:35 PM.

  4. #4
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: How to make a Loop

    Click on your attachment.

  5. #5
    Forum Contributor
    Join Date
    07-04-2017
    Location
    Phillipines
    MS-Off Ver
    2016
    Posts
    169

    Re: How to make a Loop

    Dear jason.b75

    i change code like this THANK YOU VERY MUCH.
    Private Sub cmdReturn_Click()
    Dim TimeToQuit As Long
    Dim mybox As Variant
    
    
    While TimeToQuit <> vbYes
    mybox = InputBox("How many copies?")
        If mybox = "" Then
            MsgBox ("No number of copies")
        Else
        
            With Sheets("MrrPrint")
                '.PrintPreview
                .PrintOut Copies:=mybox
            End With
            TimeToQuit = MsgBox("Do You want to Exit?", vbYesNo, Question) ' Always Show print not click "YES"
      
    'delete all
    Range("B13:O17,C16:C17,K16:K17,O16:O17,A24:Q40,M48:m50").ClearContents  ' getting error for the merge cell 
    If TimeToQuit = vbYes Then
    
        Range("B13:O17") = "" 
       Range("C16:C17").ClearContents
       Range("K16:K17") = ""
        Range("O16:O17") = ""
        Range("A24:Q40").ClearContents
        Range("M48:m50") = ""
        End If
        End If
        Wend
    End Sub

+ 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] For Each Loop (Make it Faster)
    By ExcelQuestion in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 10-03-2015, 11:36 PM
  2. Can Someone Take My VBA and make it a for loop?
    By chaddug in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-30-2013, 01:53 PM
  3. Macro to make loop to next row
    By hardrock2580 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-16-2013, 07:54 AM
  4. Make a loop that goes around around and around
    By Kristian Nilsson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-25-2012, 12:12 PM
  5. Make loop run faster
    By losmi8 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-20-2010, 01:11 AM
  6. I want to make one loop
    By David in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-11-2005, 09:05 PM
  7. [SOLVED] How to Make a Loop count by 1% not 1
    By MichaelC in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-11-2005, 10:05 PM

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