LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default ComboBox last selection

Hi yet again,

I still did not have the code correct. Missed a couple if Exit Sub's after
the MsgBox's if Year or Month not selected. Try this one. Also feel free to
get back to me again if you are still having problems with it.


Private Sub ComboYear_Enter()
'ListBox RowSource set to Sheet1.Range("A1:A151)
'which is 1900 to 2050

Me.ComboYear.DropDown
If Me.ComboYear.ListIndex - 4 = 0 Then
Me.ComboYear.TopIndex = _
Me.ComboYear.ListIndex - 4
Else
Me.ComboYear.TopIndex = 0
End If
End Sub

Private Sub ComboMonth_Enter()
'ListBox RowSource set to Sheet1.Range("B1:B12)
'which is January to December

'Because the ComboBox has 9 ListRows,
'if the value is within the last 4 rows
'then it must display the last 9 rows of the list.

Me.ComboMonth.DropDown
If Me.ComboMonth.ListIndex - 4 = 0 Then
Me.ComboMonth.TopIndex = _
Me.ComboMonth.ListIndex - 4
Else
Me.ComboMonth.TopIndex = 0
End If
End Sub

Private Sub ComboDay_Enter()

'Must select year first to determine if leap year.
If Me.ComboYear.Value = 1900 And Me.ComboYear <= 2050 Then

Select Case Me.ComboMonth.Value
Case "January", "March", "May", "July", _
"August", "October", "December"

Me.ComboDay.RowSource = _
"Sheet1!C1:C31"

Case "April", "June", "September", _
"November"

Me.ComboDay.RowSource = "Sheet1!C1:C30"

Case "February"
If Me.ComboYear.Value Mod 4 = 0 Then
'Leap year
Me.ComboDay.RowSource = _
"Sheet1!C1:C29"
Else
'Not a leap year
Me.ComboDay.RowSource = _
"Sheet1!C1:C28"
End If
Case Else
'Must select month to determine number of
'days in the dropdown.
MsgBox "Require Month selection first"
Me.ComboMonth.SetFocus
Exit Sub
End Select

Me.ComboDay.DropDown
Else
MsgBox "Require Year selection first"
Me.ComboYear.SetFocus
Exit Sub
End If

If Me.ComboDay.ListIndex - 4 = 0 Then
Me.ComboDay.TopIndex = Me.ComboDay.ListIndex - 4
Else
Me.ComboDay.TopIndex = 0
End If

End Sub
--
Regards,

OssieMac


 
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
ComboBox Selection [email protected] uk Excel Discussion (Misc queries) 1 November 14th 08 09:38 PM
fill combobox depending on selection from another combobox Adam Francis Excel Discussion (Misc queries) 2 July 24th 08 07:39 PM
Combobox items determined by the selection in another combobox Alerion Excel Programming 2 September 13th 06 01:07 PM
Combobox Selection Phil Floyd Excel Programming 0 May 6th 04 09:19 PM
Combobox selection Ian Coates Excel Programming 4 February 5th 04 09:26 AM


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