Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- ' Define the maximum number of sheets you suggest,
- ' Excel is limited by memory, depending on you available
- ' system resources and version you want to limit this
- Const MaxCopies As Long = 50
- Sub CopysheetMultipleTimes()
- Dim NoOfCopies As Variant
- Dim pCounter As Integer
- Dim tWB As Workbook
- Dim sh As Worksheet
- Dim TooMany As VbMsgBoxResult
- Dim msg As String
- Dim OKGo As Boolean
- xlSettings False ' turn off xl settings
- Set tWB = ThisWorkbook ' we are using thisworkbook
- Set sh = tWB.ActiveSheet ' we want to copy activesheet
- OKGo = True ' set this to true now, will change if too many sheets are requested
- ' create a messge
- msg = "Excel is limited by resources!" & vbNewLine
- msg = msg & "Are you sure you want to add |SHEETS| copies?"
- ' let user request number of copies
- StartPoint:
- NoOfCopies = Application.InputBox("How many copies do you what?", "Rochem Inspectors", , , , , 1)
- If NoOfCopies <> False Then ' test if x on inputbox has been pressed
- If NoOfCopies > MaxCopies Then
- TooMany = MsgBox(Replace(msg, "|SHEETS|", NoOfCopies), vbYesNo + vbCritical, "Too Many Sheets")
- If TooMany = vbNo Then GoTo StartPoint
- End If
- pCounter = 0
- Do ' create the desired number of sheets
- sh.Copy After:=tWB.Sheets(sh.Name)
- pCounter = pCounter + 1
- Loop Until pCounter = NoOfCopies
- Else
- ' x was pressed, give user feedback
- MsgBox "Copy Was Cancelled", , "Rochem Inspectors"
- End If
- xlSettings True ' restore xl settings
- End Sub
- Sub xlSettings(t As Boolean) ' sets alerts and udating to desired setting
- With Application
- .ScreenUpdating = t
- .DisplayAlerts = t
- End With
- End Sub
Add Comment
Please, Sign In to add comment