n-th Sheet is added when I try to add Sheet named as one already exisitng

pitaszek

Board Regular
Joined
Jul 20, 2012
Messages
85
Hi Guys,

I cannot understand the logic in here. I am pretty much sure it should generate and error but it does not. It just adds me another Worksheet named according to regular pattern (Sheet4, Sheet5, etc.)

I want to get an error just to skip creation with error handling and proceed to next loop iteration.

Why is that.


Code:
Sub addSheets()

Dim CurrDayBook As Workbook

Set CurrDayBook = Workbooks.Open("something.xls")

CurrDayBook.Sheets.Add.Name = "dupa"
CurrDayBook.Sheets.Add.Name = "dupa"

End sub

Regards,
Witek
 
Last edited:

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
66,003
Office Version
  1. 365
Platform
  1. Windows
The code you've posted should give an error. Are you calling that sub from another macro? or is there more to the code that you haven't shown?
 

Forum statistics

Threads
1,148,291
Messages
5,745,892
Members
423,983
Latest member
blackworx

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
Top