Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Calendar Control - Years

Hi I've used the tutorial at www.fontstuff.com/vba/vbatut07.htm to set up a
calendar for date selection in a cell.

I've used an earlier posting (12/5/2006 6:28 AM Calendar Control) by Tom
Ogilvy to pick up the Friday of the week for any date selected.

ActiveCell.Value = Format(Calendar1.Value - Weekday(Calendar1.Value,
vbSaturday), "dd-mmm-yy")

I'd like to know if it is possible limit the start and end years which can
be selected from the Calendar, say 2003 - 2012.

Can anyone help please?

Regards
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Calendar Control - Years

hi Philip

You can check the value(date) when you click on the control (click event) and when it is before 2003 jump to
the first date you allow and if it is after the last date jump to your last date.

If you need help post back

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Philip J Smith" wrote in message
...
Hi I've used the tutorial at www.fontstuff.com/vba/vbatut07.htm to set up a
calendar for date selection in a cell.

I've used an earlier posting (12/5/2006 6:28 AM Calendar Control) by Tom
Ogilvy to pick up the Friday of the week for any date selected.

ActiveCell.Value = Format(Calendar1.Value - Weekday(Calendar1.Value,
vbSaturday), "dd-mmm-yy")

I'd like to know if it is possible limit the start and end years which can
be selected from the Calendar, say 2003 - 2012.

Can anyone help please?

Regards


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Calendar Control - Years

Hi Ron.

Can you give me the syntax for the first of these so that I can replicate it
for the Second please?

Regards

Phil

"Ron de Bruin" wrote:

hi Philip

You can check the value(date) when you click on the control (click event) and when it is before 2003 jump to
the first date you allow and if it is after the last date jump to your last date.

If you need help post back

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Philip J Smith" wrote in message
...
Hi I've used the tutorial at www.fontstuff.com/vba/vbatut07.htm to set up a
calendar for date selection in a cell.

I've used an earlier posting (12/5/2006 6:28 AM Calendar Control) by Tom
Ogilvy to pick up the Friday of the week for any date selected.

ActiveCell.Value = Format(Calendar1.Value - Weekday(Calendar1.Value,
vbSaturday), "dd-mmm-yy")

I'd like to know if it is possible limit the start and end years which can
be selected from the Calendar, say 2003 - 2012.

Can anyone help please?

Regards



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Calendar Control - Years

In the click event you can use this two events

If Calendar1.Value < 37622 Then Calendar1.Value = 37622
If Calendar1.Value 41274 Then Calendar1.Value = 41274


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Philip J Smith" wrote in message
...
Hi Ron.

Can you give me the syntax for the first of these so that I can replicate it
for the Second please?

Regards

Phil

"Ron de Bruin" wrote:

hi Philip

You can check the value(date) when you click on the control (click event) and when it is before 2003 jump to
the first date you allow and if it is after the last date jump to your last date.

If you need help post back

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Philip J Smith" wrote in message
...
Hi I've used the tutorial at www.fontstuff.com/vba/vbatut07.htm to set up a
calendar for date selection in a cell.

I've used an earlier posting (12/5/2006 6:28 AM Calendar Control) by Tom
Ogilvy to pick up the Friday of the week for any date selected.

ActiveCell.Value = Format(Calendar1.Value - Weekday(Calendar1.Value,
vbSaturday), "dd-mmm-yy")

I'd like to know if it is possible limit the start and end years which can
be selected from the Calendar, say 2003 - 2012.

Can anyone help please?

Regards




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 195
Default Calendar Control - Years



Youl could do something like this

Private Sub Calendar1_Click()
If Year(Calendar1.Value) < 2003 Or Year(Calendar1.Value) 2007 Then
MsgBox "Please select Date between the Years 2003 and 2007"
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Calendar Control - Years

On Apr 24, 9:22 am, Philip J Smith
wrote:
Hi I've used the tutorial atwww.fontstuff.com/vba/vbatut07.htmto set up a
calendar for date selection in a cell.

I've used an earlier posting (12/5/2006 6:28 AM Calendar Control) by Tom
Ogilvy to pick up the Friday of the week for any date selected.

ActiveCell.Value = Format(Calendar1.Value - Weekday(Calendar1.Value,
vbSaturday), "dd-mmm-yy")

I'd like to know if it is possible limit the start and end years which can
be selected from the Calendar, say 2003 - 2012.

Can anyone help please?

Regards


This way is not particularly simple, but:
1. Remove the regular calendar month/year combo-boxes by setting "Show
Date Selectors" to "False" for the Calendar.
2. Create two new combo-boxes called MonthBox and YearBox.
3. Add the following code to the UserForm (assumed the calendar object
is called Cal):

Private Sub YearBox_Change()
Dim new_date As Date, eom_date As Date
new_date = DateSerial(YearBox, DateTime.month(Cal),
DateTime.Day(Cal))
eom_date = EoMonth(DateSerial(YearBox, DateTime.month(Cal), 1), 0)

If new_date < eom_date Then
Cal = new_date
Else
Cal = eom_date
End If
End Sub

Private Sub MonthBox_Change()
Dim new_date As Date, eom_date As Date
new_date = DateSerial(DateTime.year(Cal), MonthBox.ListIndex + 1,
DateTime.Day(Cal))
eom_date = EoMonth(DateSerial(DateTime.year(Cal),
MonthBox.ListIndex + 1, 1), 0)

If new_date < eom_date Then
Cal = new_date
Else
Cal = eom_date
End If
End Sub

Private Sub UserForm_Initialize()
' Set calendar date to now, if you want
Cal = Now()

Dim year As Integer, month As Integer
With YearBox
For year = 2003 To 2012
.AddItem year
Next year
YearBox.Text = DateTime.year(Cal)
End With

With MonthBox
For month = 1 To 12
MonthBox.AddItem MonthName(month)
Next month
MonthBox = MonthName(DateTime.month(Cal))
End With
End Sub


Make sure you enable the Analysis ToolPak - VBA addin. And I wouldn't
recommend typing into the new combo-boxes, but I don't remember if you
can lock them but still allow users to select from them.

Cheers,
David

  #7   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Calendar Control - Years

This worked for me.

Private Sub Calendar1_NewYear()
Me.Calendar1.ValueIsNull = False
If Year(Me.Calendar1) = 2012 Then
MsgBox "NO!"
Me.Calendar1.PreviousYear
End If
If Year(Me.Calendar1) <= 2003Then
MsgBox "NO!"
Me.Calendar1.NextYear
End If
End Sub

"David G" wrote in message
oups.com...
On Apr 24, 9:22 am, Philip J Smith
wrote:
Hi I've used the tutorial atwww.fontstuff.com/vba/vbatut07.htmto set up

a
calendar for date selection in a cell.

I've used an earlier posting (12/5/2006 6:28 AM Calendar Control) by Tom
Ogilvy to pick up the Friday of the week for any date selected.

ActiveCell.Value = Format(Calendar1.Value - Weekday(Calendar1.Value,
vbSaturday), "dd-mmm-yy")

I'd like to know if it is possible limit the start and end years which

can
be selected from the Calendar, say 2003 - 2012.

Can anyone help please?

Regards


This way is not particularly simple, but:
1. Remove the regular calendar month/year combo-boxes by setting "Show
Date Selectors" to "False" for the Calendar.
2. Create two new combo-boxes called MonthBox and YearBox.
3. Add the following code to the UserForm (assumed the calendar object
is called Cal):

Private Sub YearBox_Change()
Dim new_date As Date, eom_date As Date
new_date = DateSerial(YearBox, DateTime.month(Cal),
DateTime.Day(Cal))
eom_date = EoMonth(DateSerial(YearBox, DateTime.month(Cal), 1), 0)

If new_date < eom_date Then
Cal = new_date
Else
Cal = eom_date
End If
End Sub

Private Sub MonthBox_Change()
Dim new_date As Date, eom_date As Date
new_date = DateSerial(DateTime.year(Cal), MonthBox.ListIndex + 1,
DateTime.Day(Cal))
eom_date = EoMonth(DateSerial(DateTime.year(Cal),
MonthBox.ListIndex + 1, 1), 0)

If new_date < eom_date Then
Cal = new_date
Else
Cal = eom_date
End If
End Sub

Private Sub UserForm_Initialize()
' Set calendar date to now, if you want
Cal = Now()

Dim year As Integer, month As Integer
With YearBox
For year = 2003 To 2012
.AddItem year
Next year
YearBox.Text = DateTime.year(Cal)
End With

With MonthBox
For month = 1 To 12
MonthBox.AddItem MonthName(month)
Next month
MonthBox = MonthName(DateTime.month(Cal))
End With
End Sub


Make sure you enable the Analysis ToolPak - VBA addin. And I wouldn't
recommend typing into the new combo-boxes, but I don't remember if you
can lock them but still allow users to select from them.

Cheers,
David



Reply
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
Control disappeared problem - specifically, the Calendar Control JMMach[_2_] Excel Programming 0 December 16th 05 01:53 AM
How do I add an extra day to a calendar every four years paddymack New Users to Excel 3 May 31st 05 10:00 AM
excel calendar years whowatwerwyhow Excel Discussion (Misc queries) 1 May 16th 05 12:28 PM
excel calendar years whowatwerwyhow Excel Discussion (Misc queries) 0 May 16th 05 12:19 PM
Calendar Control: Can't exit design mode because control can't be created Rone Excel Programming 0 May 24th 04 04:01 PM


All times are GMT +1. The time now is 02:44 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"