+ Reply to Thread
Results 1 to 6 of 6

Combobox for birthdays

Hybrid View

richard.dolis Combobox for birthdays 03-01-2017, 12:08 AM
Logit Re: Combobox for birthdays 03-01-2017, 12:56 AM
Maudibe Re: Combobox for birthdays 03-01-2017, 01:33 AM
richard.dolis Re: Combobox for birthdays 03-01-2017, 10:07 PM
jindon Re: Combobox for birthdays 03-01-2017, 10:51 PM
Maudibe Re: Combobox for birthdays 03-02-2017, 06:30 PM
  1. #1
    Registered User
    Join Date
    02-20-2017
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    4

    Combobox for birthdays

    Hi

    Good day to all!

    i have 3 combobox.. cmbMonth(Month), cmbDay(Day) and cmbYear(Year) and the purpose of this is to set up their birthdays.

    Is there any vba code for this?


    thanks in advance
    Attached Images Attached Images

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,485

    Re: Combobox for birthdays

    Here is one way :

    For a UserForm:

    Option Explicit
    'Clears and Initializes the form when first loaded.
    Private Sub UserForm_Initialize()
    With ComboBox1
            .Clear
            .AddItem "January"
            .AddItem "February"
            .AddItem "March"
            .AddItem "April"
            .AddItem "May"
            .AddItem "June"
            .AddItem "July"
            .AddItem "August"
            .AddItem "September"
            .AddItem "October"
            .AddItem "November"
            .AddItem "December"
        End With
        With ComboBox2
            .Clear
            .AddItem "1"
            .AddItem "2"
            .AddItem "3"
            .AddItem "4"
            .AddItem "5"
            .AddItem "6"
            .AddItem "7"
            .AddItem "8"
            .AddItem "9"
            .AddItem "10"
            .AddItem "11"
            .AddItem "13"
            .AddItem "14"
            .AddItem "15"
            .AddItem "16"
            .AddItem "17"
            .AddItem "18"
            .AddItem "19"
            .AddItem "20"
            .AddItem "21"
            .AddItem "22"
            .AddItem "23"
            .AddItem "24"
            .AddItem "25"
            .AddItem "26"
            .AddItem "27"
            .AddItem "28"
            .AddItem "29"
            .AddItem "30"
            .AddItem "31"
        End With
        
        With ComboBox3
            .Clear
            .AddItem "2017"
            .AddItem "2018"
            .AddItem "2019"
            .AddItem "2020"
            .AddItem "2021"
            .AddItem "2022"
            .AddItem "2023"
            .AddItem "2024"
            .AddItem "2025"
            .AddItem "2026"
            .AddItem "2027"
            .AddItem "2028"
            .AddItem "2029"
            .AddItem "2030"
            
        End With
    
    
    End Sub

    For a worksheet :

    Option Explicit
    
    Private Sub Worksheet_Activate()
    With ComboBox1
            .Clear
            .AddItem "January"
            .AddItem "February"
            .AddItem "March"
            .AddItem "April"
            .AddItem "May"
            .AddItem "June"
            .AddItem "July"
            .AddItem "August"
            .AddItem "September"
            .AddItem "October"
            .AddItem "November"
            .AddItem "December"
        End With
        With ComboBox2
            .Clear
            .AddItem "1"
            .AddItem "2"
            .AddItem "3"
            .AddItem "4"
            .AddItem "5"
            .AddItem "6"
            .AddItem "7"
            .AddItem "8"
            .AddItem "9"
            .AddItem "10"
            .AddItem "11"
            .AddItem "13"
            .AddItem "14"
            .AddItem "15"
            .AddItem "16"
            .AddItem "17"
            .AddItem "18"
            .AddItem "19"
            .AddItem "20"
            .AddItem "21"
            .AddItem "22"
            .AddItem "23"
            .AddItem "24"
            .AddItem "25"
            .AddItem "26"
            .AddItem "27"
            .AddItem "28"
            .AddItem "29"
            .AddItem "30"
            .AddItem "31"
        End With
        
        With ComboBox3
            .Clear
            .AddItem "2017"
            .AddItem "2018"
            .AddItem "2019"
            .AddItem "2020"
            .AddItem "2021"
            .AddItem "2022"
            .AddItem "2023"
            .AddItem "2024"
            .AddItem "2025"
            .AddItem "2026"
            .AddItem "2027"
            .AddItem "2028"
            .AddItem "2029"
            .AddItem "2030"
            
        End With
    End Sub
    Attached Files Attached Files

  3. #3
    Valued Forum Contributor Maudibe's Avatar
    Join Date
    12-21-2016
    Location
    USA
    MS-Off Ver
    2010-2013
    Posts
    326

    Re: Combobox for birthdays

    Richard,

    The following code will take into consideration leap years and the days for each month based on the selection using named ranges on sheet 1. The userform is called Userform1, 3 comboboxes (combobox1, 2, and 3), and a command button (CommandButton1).

    HTH,
    Maud

    Private Sub ComboBox1_Change()
    ComboBox2.Enabled = True
    ComboBox2.RowSource = "Mo"
    End Sub
    
    Private Sub ComboBox2_Change()
    ComboBox3.Enabled = True
    leap = Val(ComboBox1.Value) Mod 4
    Select Case ComboBox2.Value
        Case 1, 3, 5, 7, 8, 10, 12
    
            ComboBox3.RowSource = "Days4"
        Case 4, 6, 9, 11
            ComboBox3.RowSource = "Days3"
        Case 2
            If leap = 0 Then ComboBox3.RowSource = "Days2" Else ComboBox3.RowSource = "Days1"
    End Select
    End Sub
    
    Private Sub CommandButton1_Click()
    If ComboBox1.Value = "" Or ComboBox2.Value = "" Or ComboBox3.Value = "" Then Exit Sub
    MsgBox "d/m/yyyy" & Chr(13) & _
    ComboBox2.Value & "/" & ComboBox3.Value & "/" & ComboBox1.Value
    Unload Me
    End Sub
    
    Private Sub UserForm_Initialize()
    ComboBox1.RowSource = "Yr"
    ComboBox2.Enabled = False
    ComboBox2.Enabled = False
    End Sub
    HTH,
    Maud
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    02-20-2017
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    4

    Re: Combobox for birthdays

    Hi Maud, It worked but I want the value in the Comboboxes couldn't be changed before I click the OK button.
    Is there any way that the value in comboboxes should be on the list? and will not proceed if not?

    By the way, thank you for your help.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Combobox for birthdays

    3 Comboboxes (Named ; ComboBox1, ComboBox2, ComboBox3)
    ComboBox1 for Year, ComboBox2 for Month, ComboBox3 for Day
    Private Sub UserForm_Initialize()
        With Me.ComboBox1
            .List = Evaluate("row(" & Year(Date) - 100 & ":" & Year(Date) & ")")
            .ListIndex = 60
        End With
        Me.ComboBox2.List = Evaluate("index(text(""2017/""&row(1:12)&""/1"",""mmmm""),)")
    End Sub
    Private Sub ComboBox1_Click()
        ComboBox2_Click
    End Sub
    Private Sub ComboBox2_Click()
        Dim endDay As Long
        If (Me.ComboBox1.ListIndex = -1) + (Me.ComboBox2.ListIndex = -1) Then Exit Sub
        endDay = Day(WorksheetFunction.EoMonth(Me.ComboBox1.Value & "/" & Me.ComboBox2.ListIndex + 1 & "/1", 0))
        Me.ComboBox3.List = Evaluate("row(1:" & endDay & ")")
    End Sub
    Last edited by jindon; 03-01-2017 at 10:58 PM.

  6. #6
    Valued Forum Contributor Maudibe's Avatar
    Join Date
    12-21-2016
    Location
    USA
    MS-Off Ver
    2010-2013
    Posts
    326

    Re: Combobox for birthdays

    Richard,

    When the form opens, the month and day comboboxes are disabled. When a year is selected, the month becomes enabled. When the month is selected, the day becomes enabled. The purpose is to let each combobox load the appropriate range to account for the leap years. The date can be changed prior to clicking OK.

    HTH,
    Maud

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Adding Birthdays
    By pavalon in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 07-29-2015, 04:20 PM
  2. Birthdays Alert
    By MGharieb in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-21-2014, 03:01 PM
  3. Upcoming Birthdays
    By campersand in forum Excel General
    Replies: 14
    Last Post: 09-05-2014, 11:41 AM
  4. january 1 birthdays
    By martindwilson in forum The Water Cooler
    Replies: 24
    Last Post: 12-03-2010, 12:02 PM
  5. Coincident Birthdays
    By milleran in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 01-20-2010, 03:38 PM
  6. Birthdays
    By Platski in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-01-2006, 02:20 PM
  7. Highlight birthdays
    By jocker in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 01-03-2006, 12:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1