View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default Please help with my code

I am entirely unclear what the 'if then else' structure is intended to do? If
I wanted to delete a sheet I would be inclined to do something like this

application.displayalerts = false
on error resume next
Activeworkbook.Sheets("Sheet1").Delete
on error goto 0
application.displayalerts = true
--
HTH...

Jim Thomlinson


"AccessHelp" wrote:

I have the following code:

Elseif Activeworkbook.sheets.names = "Sheet 1" Then
Sheets("Sheet 1").Delete

Basically, I have Workbook A and Workbook B. In Workbook A, I created a
user form with various functionalities, and the code above is part of the
user form. When I open Workbook A in the same instance as Workbook B, the
user form will open on the Workbook B. When I click on any button on the
user form, the code will execute on Workbook B.

The purpose of the code above is to check whether "Sheet 1" exists in
Workbook B. If exist, delete "Sheet 1". I am having problem with the code
(Elseif Activeworkbook.Sheets.Names = "Sheet 1" Then) to check whether "Sheet
1" exists.

Can someone help me with the code? Below is the structure of my entire code:

Private Sub cmdTest_Click()
If ....... Then
.......
Elseif Activeworkbook.Sheets.Names = "Sheet 1" Then
Sheets("Sheet 1").Delete
Else
........
End If
End Sub

Thanks.