Excel VBA Run-time error '13"

ThisIsMachiel

New Member
Joined
Mar 26, 2018
Messages
2
Hi,

I created a macro, and when I run it i getting the runtime error 13 Type mismatch. I'm relatively new, so hopefully it will be an Easy solution. The idea of this part of the macro is to let the user open another excel file and copy the testsheet to the active workbook. The runtime error happens on the bold red line.

Sub CreateNewWorksheet()
'Variables
Dim ORMWorksheetLocation As Variant
Dim Thiswb As Workbook
Set Thiswb = ActiveWorkbook
Dim Testsheet1 As Worksheet
Set Testsheet1 = ActiveSheet


'Rename worksheet
Testsheet1.Name = "TestSheet1"

'Choose excel file to open
ORMWorksheetLocation = Application.GetOpenFilename(FileFIlter:="Excel Files,*.xl*;*.xm*")
If ORMWorksheetLocation <> False Then
Workbooks.Open Filename:=ORMWorksheetLocation
Else
MsgBox ("You have not selected a File")
End If


'Copy ORM Testsheet
ActiveSheet.Copy After:=Workbooks(Thiswb).Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = "ORM testsheet HY1"
ActiveWorkbook.Close


End Sub

As far as I could find the error happens because of the Workbooks(Thiswb), but because i defined the variable Thiswb as a workbook, I'm not sure why

Any help is welcome. This is written in excel 2010
Thanks!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try this.
Code:
ActiveSheet.Copy After:=Thiswb.Sheets(Thiswb.Sheets.Count)
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top