Application defined error or object defined error - VBA

Kaps_mr2

Well-known Member
Joined
Jul 5, 2008
Messages
1,589
Office Version
  1. 365
Platform
  1. Windows
Dear All,

I am getting an application defined or object defined error on the line in bold below. Can anybody shed any light ? thanks

Kaps

Rich (BB code):
 If does_sheet_exist(trustworkbook, "QIPP") = True Then
    
    MsgBox "QIPP " & i & " " & trust_code
    
        trustworkbook.Sheets("QIPP").Name = trust_code
        
        quipp_template_file.Sheets.Add before:=quipp_template_file.Sheets("end")
        
        ActiveSheet.Name = trust_code
        
        trustworkbook.Sheets(trust_code).Range("a1:az300").Copy quipp_template_file.Sheets(trust_code).Range("a1")
            
    End If
The function does_sheet_exist is defined as:-

Rich (BB code):
Public Function does_sheet_exist(file_to_search As Workbook, sheet_to_find) As Boolean
does_sheet_exist = False
Dim i As Long
Dim no_of_sheets As Long

no_of_sheets = file_to_search.Sheets.Count

For i = 1 To no_of_sheets

    If file_to_search.Sheets(i).Name = sheet_to_find Then
        does_sheet_exist = True
        Exit For
    End If

Next


End Function
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Are you sure you aren't trying to name a worksheet with the same name as an existing worksheet?

Or an invalid name?
 
Upvote 0
Norie,

Thanks. No the value of trustcode is "5A7" - whilst the original sheet is called "QIPP".

Kind Regards

Kaps
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,820
Members
452,946
Latest member
JoseDavid

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