Copy sheet to workbook throwing runtime error 13 "Type Mismatch"

Gingertrees

Well-known Member
Joined
Sep 21, 2009
Messages
697
No idea what changed, but now this gets stuck at the Copy after line. Throws Runtime Error 13: Type Mismatch.
Could someone let me know WHY and help me fix it??? Thanks in advance. :
Rich (BB code):
Sub OpenCopyOrange()
'////Sub 1//////'////Sub 1//////'////Sub 1//////
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationAutomatic


Dim tempfiletocopy As Variant  
Dim tempfileName As String
Dim tempsheet As Worksheet
Dim OrangeWb As Workbook


Set OrangeWb = ActiveWorkbook


tempfiletocopy = Application.GetOpenFilename
Workbooks.Open tempfiletocopy
tempfileName = ActiveWorkbook.Name
Set tempsheet = Workbooks(tempfileName).ActiveSheet
tempsheet.Name = "Orange"


Sheets("Orange").Copy After:=Workbooks(OrangeWb).Sheets(ThisWorkbook.Sheets.Count)
'////Info box appears stating: Workbooks(OrangeWb).Sheets(ThisWorkbook.Sheets.Count) = <type mismatch="">
'////
If Not SheetExists("Orange" & Sheets.Count) Then
ActiveSheet.Name = "Orange" & Sheets.Count
Else
ActiveSheet.Name = "Orange" & (Sheets.Count * 3)
End If
'///this prevents the "sheet name exists" error


Workbooks(tempfileName).Close savechanges:=False
'///closes file the new sheet was copied from


Application.ScreenUpdating = True
Application.DisplayAlerts = True
'//reset the speed tricks


End Sub

This is related to the code Norie helped me with recently (see http://www.mrexcel.com/forum/excel-...-end-copying-middle-second-place-instead.html). It worked then, but I've added and deleted other worksheets and certainly done other bad stuff since then.</type>
 

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
Add this back in above the broken line:

Sheets("Orange").Select

It adds to the code, but I've seen a similiar issue before and think this addition resolved it.
 
Upvote 0
Tried that - still throwing the same error at the same place. :( Other ideas?

Okay, ignore that addition. Are you working in two workbooks, if not it looks like your code should read this:

Sheets("Orange").Copy After:=Workbooks(tempfileName).Sheets(ThisWorkbook.Sheets.Count)
 
Upvote 0
No idea what changed, but now this gets stuck at the Copy after line. Throws Runtime Error 13: Type Mismatch.
Could someone let me know WHY and help me fix it??? Thanks in advance. :
Rich (BB code):
Sub OpenCopyOrange()
'////Sub 1//////'////Sub 1//////'////Sub 1//////
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationAutomatic


Dim tempfiletocopy As Variant  
Dim tempfileName As String
Dim tempsheet As Worksheet
Dim OrangeWb As Workbook


Set OrangeWb = ActiveWorkbook


tempfiletocopy = Application.GetOpenFilename
Workbooks.Open tempfiletocopy
tempfileName = ActiveWorkbook.Name
Set tempsheet = Workbooks(tempfileName).ActiveSheet
tempsheet.Name = "Orange"


Sheets("Orange").Copy After:=Workbooks(OrangeWb).Sheets(ThisWorkbook.Sheets.Count)
'////Info box appears stating: Workbooks(OrangeWb).Sheets(ThisWorkbook.Sheets.Count) = <type mismatch="">
'////
If Not SheetExists("Orange" & Sheets.Count) Then
ActiveSheet.Name = "Orange" & Sheets.Count
Else
ActiveSheet.Name = "Orange" & (Sheets.Count * 3)
End If
'///this prevents the "sheet name exists" error


Workbooks(tempfileName).Close savechanges:=False
'///closes file the new sheet was copied from


Application.ScreenUpdating = True
Application.DisplayAlerts = True
'//reset the speed tricks


End Sub

This is related to the code Norie helped me with recently (see http://www.mrexcel.com/forum/excel-...-end-copying-middle-second-place-instead.html). It worked then, but I've added and deleted other worksheets and certainly done other bad stuff since then.</type>
OrangeWb is a workbook, not a workbook name. Change this:

Sheets("Orange").Copy After:=Workbooks(OrangeWb).Sheets(ThisWorkbook.Sheets.Count)

to this:

Sheets("Orange").Copy After:=OrangeWb.Sheets(Sheets.Count)
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

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