dave3009

GuaravGarg

May 24th, 2020
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Sub CopysheetMultipleTimes()
  4. Dim NoOfCopies As Variant
  5. Dim pCounter As Integer
  6. Dim tWB As Workbook
  7. Dim sh As Worksheet
  8.  
  9. xlSettings False ' turn off xl settings
  10.  
  11. Set tWB = ThisWorkbook ' we are using thisworkbook
  12. Set sh = tWB.ActiveSheet ' we want to copy activesheet
  13.  
  14. ' let user request number of copies
  15. NoOfCopies = Application.InputBox("How many copies do you what?", "Rochem Inspectors", , , , , 1)
  16.  
  17.  
  18.     If NoOfCopies <> False Then ' test if x on inputbox has been pressed
  19.        pCounter = 0
  20.         Do ' create the desired number of sheets
  21.            sh.Copy After:=tWB.Sheets(sh.Name)
  22.             pCounter = pCounter + 1
  23.         Loop Until pCounter = NoOfCopies
  24.     Else
  25.         ' x was pressed, give user feedback
  26.        MsgBox "Copy Was Cancelled", , "Rochem Inspectors"
  27.     End If
  28. xlSettings True ' restore xl settings
  29. End Sub
  30.  
  31. Sub xlSettings(t As Boolean) ' sets alerts and udating to desired setting
  32. With Application
  33.     .ScreenUpdating = t
  34.     .DisplayAlerts = t
  35. End With
  36. End Sub
Add Comment
Please, Sign In to add comment