LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Trying to stop making a new sheet

I have the following code but can't get it to work. Essentially, when the
macro is run a new sheet is made and the new name assigned is the day that
the macro is run. I want it to stop, not make the new sheet and close the
UserForm if a sheet of that name already exists (along with the msgbox
explaining what happend). I assume that the problem is common from different
data types and have tried CInt, CVar, etc... with no luck. Where am I going
wrong.
Thanks in advance for any assistance.
Brad K

Private Sub cbOK_Click()
Dim i As Integer
Dim j As Integer
Dim xDay As Integer
Dim xMonth As Integer
Dim xYear As Integer

i = Worksheets.Count
For j = 1 To i
If Worksheets(j).Name = Day(Calendar1.Value) Then
MsgBox "The date you have chosen already exists as a sheet."
Unload Me
End If
Next j
Worksheets("Template").Copy Befo=Worksheets(i)
xYear = Year(Calendar1.Value)
xMonth = Month(Calendar1.Value)
xDay = Day(Calendar1.Value)
Cells(7, 9) = xMonth & "/" & xYear
Cells(7, 9).NumberFormat = "mmmm/yy"
Worksheets(i).Name = xDay
Unload Me
End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to stop XL from adding the Path Sring to Sheet-to-Sheet Links [email protected] Excel Discussion (Misc queries) 5 August 18th 06 01:46 PM
How can I stop excel from automatically making hyperlinks MAB5025 Excel Discussion (Misc queries) 5 May 23rd 06 03:53 AM
How do I stop Excel from making copies of files? wlewismba Excel Discussion (Misc queries) 1 April 30th 05 04:28 PM
stop automatically making email address lily Excel Discussion (Misc queries) 1 March 23rd 05 04:53 AM
what is the keys to stop recording, i cant press it when making a. Lante Excel Discussion (Misc queries) 1 January 3rd 05 09:15 PM


All times are GMT +1. The time now is 10:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"