I have a userform that allows the user to select 1 or more sheets to import from a different workbook. It works great if only 1 sheet is selected.
However, if 2 or more are selected, i get: Run-time error '9': Subscript out of range
It references the
Any thoughts on this would be greatly appreciated!
Code:
For Each cntrlx In NewTakeOffUserForm.MaterialFrame.Controls
If TypeOf cntrlx Is msforms.CheckBox And cntrlx = True Then
If Not databook Is Nothing Then
Else
Set databook = Workbooks.Open(directory & "\" & filename)
End If
Set datasheet = databook.Sheets(cntrlx.Caption)
[U][B]Sheets(cntrlx.Caption).Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count())[/B][/U]
With ActiveSheet
.Range("SystemLabel").Value = SystemTextBox.Value
.Name = SystemTextBox.Value & " " & cntrlx.Caption
.Range("CategoryLabel").Value = CategoryComboBox.Value
End With
Set datasheet = Nothing
End If
Next cntrlx
However, if 2 or more are selected, i get: Run-time error '9': Subscript out of range
It references the
Code:
[U][B]Sheets(cntrlx.Caption).Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count())[/B][/U]
Any thoughts on this would be greatly appreciated!