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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
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?
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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