Avoid VBA errors with the same page name

knaabis

Active Member
Joined
Apr 25, 2006
Messages
254
Office Version
  1. 2013
Platform
  1. Windows
How to integreate in this VBA - when I try to create a page by the existing name, then that VBA is suspended?

Sub SheetNumber()
DialogSheets("Dialog1").Show
Sheets.Add.Name = DialogSheets("Dialog1").EditBoxes("4").Text
With DialogSheets("Dialog1")
.EditBoxes("4").Text = ""
End With
End Sub
 
How to get functionality to this VBA, if sheet name exist?

Sub SheetNumber()
DialogSheets("Dialog1").Show
Sheets.Add.Name = DialogSheets("Dialog1").EditBoxes("4").Text
With DialogSheets("Dialog1")
.EditBoxes("4").Text = ""
End With
End Sub
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
knaabis

Can you please tell us what you are trying to do with this code?

Not just the part about checking to see if an existing worksheet has the same name as the name you are trying to use for the new sheet.

One thing in particular, why are you using DialogSheets?
 
Upvote 0
I each new worksheet i create special information input form with special formating and with some buttons.
I has a worksheet with many sheets with very similar names.
New sheet i create by VBA and sheet name add also by VBA.
When i create the new sheet and sheet with this new name exist , then i get error in VBA...
 
Upvote 0
Well that's already been answered by Weaver.:eek:
 
Upvote 0
BUT how to integrate this Weaver function in my VBA?
 
Upvote 0
Something like this, maybe?

Code:
Sub SheetNumber()
    If Not sheetExists(DialogSheets("Dialog1").EditBoxes("4").Text) Then
        DialogSheets("Dialog1").Show
        Sheets.Add.Name = DialogSheets("Dialog1").EditBoxes("4").Text
        With DialogSheets("Dialog1")
            .EditBoxes("4").Text = ""
        End With
    End If
End Sub

Function sheetExists(ByVal shtName As String) As Boolean
    On Error Resume Next
    sheetExists = ActiveWorkbook.Sheets(shtName).Name <> ""
End Function
 
Upvote 0
Error in this line - Function sheetExists(ByVal shtName As String) As Boolean
Compile error: ambiguous name detected...
 
Upvote 0
Then you already have a function or sub called sheetExists
 
Upvote 0
Anyway, if I enter an existing sheet number, i get error in this place:
Sheets.Add.Name = DialogSheets("Dialog1").EditBoxes("4").Text
 
Upvote 0

Forum statistics

Threads
1,215,062
Messages
6,122,925
Members
449,094
Latest member
teemeren

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