rjplante
Well-known Member
- Joined
- Oct 31, 2008
- Messages
- 574
- Office Version
- 365
- Platform
- Windows
I have a list of all the worksheets in my workbook on tab 1. I want the user to put a number next to the sheet in column B and have the macro copy the selected worksheet one less times than the number listed. If in the end I want 3 copies of the worksheet, I want to make two copies of the selected sheet. When I run my macro it fails on this line (wsN = ActiveSheet) with a run time error '91': object variable or with block variable not set. How do I fix this?
Thanks for the help!
Code:
Dim CopyCnt As Integer
Dim wsCnt As Integer
Dim wsN As Worksheet
' Find worksheet that matches text
For Each Sheet In ActiveWorkbook.Sheets
If Sheet.Name Like "*" & ActiveCell.Offset(0, 13).Value & "*" Then
Sheet.Activate
wsN = ActiveSheet
Exit For
End If
Next
' Duplicate selected worksheet
n = 1
Do Until n = CopyCnt
wsN.Copy After:=wsN
n = n + 1
Loop
Thanks for the help!