Hello,

I have a small function with which I am copying worksheets it looks as follows:
Public NAAMSNAME As String
Public NAAMSSHEET As String

Public Sub Btn_AddParts_Click()

If OptBut_APF500M = True Then
NAAMSNAME = OptBut_APF500M.Caption
NAAMSSHEET = "APF500M-APF511M"
CopyWorkSheet

End If


If OptBut_APF501M = True Then
NAAMSNAME = OptBut_APF502M.Caption
NAAMSSHEET = "APF500M-APF511M"
CopyWorkSheet

End If

If OptBut_APF502M = True Then
NAAMSNAME = OptBut_APF502M.Caption
NAAMSSHEET = "APF500M-APF511M"
CopyWorkSheet

End If

End Sub

Public Sub CopyWorkSheet()
Dim wSheet As Worksheet
On Error Resume Next
Set wSheet = Worksheets(NAAMSNAME)
If wSheet Is Nothing Then
        Sheets(NAAMSSHEET).Copy After:=Sheets(NAAMSSHEET)
        ActiveSheet.Name = NAAMSNAME
Else
        
End If
On Error GoTo 0
End Sub
Now as you can see the CopyWorksheet function is called a few times. But for whatever reason this doesnt work. If I remove the "NAAMSNAME" and "NAAMSSHEET" and replace them with text than it will work.

Oh and if it needs to be said, this is supposed to take the caption of a OptionButton, search the workbook for hseets that match the caption text and if there is one do nothing if there isnt. It is supposed to copy a designated sheet and rename it to the Option Button Caption.

Any ideas?