+ Reply to Thread
Results 1 to 4 of 4

Using Date picker in Visual Basic with a Userform

  1. #1
    Registered User
    Join Date
    01-30-2021
    Location
    Missouri
    MS-Off Ver
    Microsoft Family
    Posts
    1

    Using Date picker in Visual Basic with a Userform

    What im wanting to do is this (There are 6 Datepickers in the workbook)

    1. I want to be able to when i open a userform in excel i want to have the Date picker to default to the current date.

    2. I want know in the code that im about to post what code i should use to make this happen and where to put it in the macro. This code is in the initialize part of the workbook.

    3. Im going to attach the excel file also.

    4.The Date picker i have used is the one that is in the tool box in the visual basic.

    5. If you cant tell me how to do this with the toolbox please let me know how it can be done with my code that i have by adding more code or how ever.



    Thanks






    Private Sub UserForm_Initialize()
    'Combobox1
    With ComboBox1
    .AddItem "JANUARY"
    .AddItem "FEBUARY"
    .AddItem "MARCH"
    .AddItem "APRIL"
    .AddItem "MAY"
    .AddItem "JUNE"
    .AddItem "JULY"
    .AddItem "AUGUST"
    .AddItem "SEPTEMBER"
    .AddItem "OCTOBER"
    .AddItem "NOVEMBER"
    .AddItem "DECEMBER"
    End With

    'ComboBox2
    With ComboBox2
    .AddItem "JANUARY"
    .AddItem "FEBUARY"
    .AddItem "MARCH"
    .AddItem "APRIL"
    .AddItem "MAY"
    .AddItem "JUNE"
    .AddItem "JULY"
    .AddItem "AUGUST"
    .AddItem "SEPTEMBER"
    .AddItem "OCTOBER"
    .AddItem "NOVEMBER"
    .AddItem "DECEMBER"
    End With

    'ComboBox3

    With Sheets("OPTIONS PAGE")
    Me.ComboBox3.List = .Range("C2", .Cells(.Rows.Count, "C").End(xlUp)).Value
    End With

    'ComboBox4
    With ComboBox4
    .AddItem "UTILITY"
    .AddItem "RESALE"
    .AddItem "INSURANCE"
    .AddItem "SUPPLIES"
    .AddItem "TAXES"
    .AddItem "CO2"
    .AddItem "LICENSE"
    .AddItem "EQUIPMENT"
    .AddItem "MAINTENACE"
    .AddItem "MEMBERSHIP"
    .AddItem "LABOR"
    .AddItem "REPAIRS"
    .AddItem "MERCHANT LIC"
    End With



    'Combobox5
    With ComboBox5
    .AddItem "JANUARY"
    .AddItem "FEBUARY"
    .AddItem "MARCH"
    .AddItem "APRIL"
    .AddItem "MAY"
    .AddItem "JUNE"
    .AddItem "JULY"
    .AddItem "AUGUST"
    .AddItem "SEPTEMBER"
    .AddItem "OCTOBER"
    .AddItem "NOVEMBER"
    .AddItem "DECEMBER"
    End With

    'Combobox 6
    With ComboBox6
    .AddItem "Sandy"
    .AddItem "Kim"
    End With

    'Combobox 7
    With ComboBox7
    .AddItem "JANUARY"
    .AddItem "FEBUARY"
    .AddItem "MARCH"
    .AddItem "APRIL"
    .AddItem "MAY"
    .AddItem "JUNE"
    .AddItem "JULY"
    .AddItem "AUGUST"
    .AddItem "SEPTEMBER"
    .AddItem "OCTOBER"
    .AddItem "NOVEMBER"
    .AddItem "DECEMBER"
    End With

    'Combobox 8
    With ComboBox8
    .AddItem "JANUARY"
    .AddItem "FEBUARY"
    .AddItem "MARCH"
    .AddItem "APRIL"
    .AddItem "MAY"
    .AddItem "JUNE"
    .AddItem "JULY"
    .AddItem "AUGUST"
    .AddItem "SEPTEMBER"
    .AddItem "OCTOBER"
    .AddItem "NOVEMBER"
    .AddItem "DECEMBER"
    End With

    'Combobox 9
    With ComboBox9
    .AddItem "JANUARY"
    .AddItem "FEBUARY"
    .AddItem "MARCH"
    .AddItem "APRIL"
    .AddItem "MAY"
    .AddItem "JUNE"
    .AddItem "JULY"
    .AddItem "AUGUST"
    .AddItem "SEPTEMBER"
    .AddItem "OCTOBER"
    .AddItem "NOVEMBER"
    .AddItem "DECEMBER"
    End With

    'Combobox 10
    With ComboBox10
    .AddItem "21.00"
    .AddItem "35.00"
    .AddItem "38.50"
    .AddItem "42.00"
    .AddItem "77.00"
    End With

    'Combobox 11
    With Sheets("OPTIONS PAGE")
    Me.ComboBox11.List = .Range("G2", .Cells(.Rows.Count, "G").End(xlUp)).Value
    End With


    End Sub

    'Reciepts

    Private Sub CommandButton1_Click()
    Dim lr As Long
    Application.ScreenUpdating = True
    Sheet = ComboBox1.Text
    If Sheet = "" Then
    MsgBox "Select Month", vbInformation, "Error"

    Exit Sub
    End If

    Sheets(Sheet).Select
    Set findBlank = Range("H2:H53").Find(What:="", lookat:=xlWhole)
    findBlank.Select
    ActiveCell.Value = DTPicker1.Value
    ActiveCell.Offset(0, 1).Value = TextBox1.Text
    ActiveCell.Offset(0, 2).Value = TextBox2.Text
    ActiveCell.Offset(0, 3).Value = TextBox3.Text

    'Sort Reciepts
    Sheets(Sheet).Range("H2:L53").Sort key1:=Range("H2"), order1:=xlAscending, Header:=xlYes




    'Clear Form
    TextBox1.Text = ""
    TextBox2.Text = ""
    TextBox3.Text = ""

    End Sub

    'Expences

    Private Sub CommandButton2_Click()
    Dim lr As Long
    Application.ScreenUpdating = True
    Sheet = ComboBox2.Text
    If Sheet = "" Then
    MsgBox "Select Month", vbInformation, "Error"
    Exit Sub
    End If

    Sheets(Sheet).Select
    Set findBlank = Range("A2:A53").Find(What:="", lookat:=xlWhole)
    findBlank.Select

    If ComboBox3 <> "" Then
    ActiveCell.Value = DTPicker2.Value
    ActiveCell.Offset(0, 1).Value = TextBox4.Text
    ActiveCell.Offset(0, 2).Value = ComboBox3.Text
    ActiveCell.Offset(0, 3).Value = ComboBox4.Text
    ActiveCell.Offset(0, 4).Value = TextBox5.Text
    ActiveCell.Offset(0, 5).Value = TextBox6.Text
    End If

    'CC fees
    If TextBox7.Text <> "" Then
    Set findBlank = Range("S2:S53").Find(What:="", lookat:=xlWhole)
    findBlank.Select
    ActiveCell.Value = DTPicker2.Value
    ActiveCell.Offset(0, 1).Value = TextBox7.Text

    'Sort CC fees
    Sheets(Sheet).Range("S2:T53").Sort key1:=Range("S2"), order1:=xlAscending, Header:=xlYes
    End If





    'Add UTILITY
    If ComboBox4 = "UTILITY" Then
    Set findBlank = Range("Z2:Z23").Find(What:="", lookat:=xlWhole)
    findBlank.Select
    ActiveCell.Value = DTPicker2.Value
    ActiveCell.Offset(0, 1).Value = TextBox5.Text

    'Sort Utility
    Sheets(Sheet).Range("Z2:AA23").Sort key1:=Range("Z2"), order1:=xlAscending, Header:=xlYes
    End If


    'Add INSURANCE
    If ComboBox4 = "INSURANCE" Then
    Set findBlank = Range("Z28:Z53").Find(What:="", lookat:=xlWhole)
    findBlank.Select
    ActiveCell.Value = DTPicker2.Value
    ActiveCell.Offset(0, 1).Value = TextBox5.Text

    'Sort Insurance
    Sheets(Sheet).Range("Z28:AA53").Sort key1:=Range("Z28"), order1:=xlAscending, Header:=xlYes
    End If


    'Add TAXES PAID
    If ComboBox4 = "TAXES" Then
    Set findBlank = Range("AK42:AK53").Find(What:="", lookat:=xlWhole)
    findBlank.Select
    ActiveCell.Value = DTPicker2.Value
    ActiveCell.Offset(0, 1).Value = TextBox5.Text

    'Sort Taxes
    Sheets(Sheet).Range("AK42:AL53").Sort key1:=Range("AK28"), order1:=xlAscending, Header:=xlYes
    End If


    'Sort Expences
    Sheets(Sheet).Range("A2:F53").Sort key1:=Range("A2"), order1:=xlAscending, Header:=xlYes


    'Clear Form
    TextBox4.Text = ""
    ComboBox3.Text = ""
    ComboBox4.Text = ""
    TextBox5.Text = ""
    TextBox6.Text = ""
    TextBox7.Text = ""

    End Sub

    'Labor Costs
    Private Sub CommandButton3_Click()
    Dim lr As Long
    Dim findDate As Date
    Application.ScreenUpdating = True
    Sheet = ComboBox5.Text
    If Sheet = "" Then
    MsgBox "Select Month", vbInformation, "Error"
    Exit Sub
    End If
    Sheets(Sheet).Select
    iDate = Trim(DTPicker3.Value)

    'set findDate = Range("V3:V53").Find(What:=iDate, LookAt:=xlWhole)
    Range("V3").Select
    For i = 1 To 51
    If Trim(ActiveCell.Value) = iDate Then
    myName = ComboBox6.Text
    If myName = "Sandy" Then myCol = "W"
    If myName = "Kim" Then myCol = "X"
    Range(myCol & ActiveCell.Row).Value = ComboBox10.Value
    'Sort Labor Costs
    Sheets(Sheet).Range("V2:X53").Sort key1:=Range("V2"), order1:=xlAscending, Header:=xlYes
    'Clear Form
    ComboBox6.Text = ""
    ComboBox10.Text = ""
    Exit Sub
    Else
    'i = i + 1
    Range("V" & i + 2).Select
    End If
    Next
    lr = Range("V53").End(xlUp).Row + 1
    myName = ComboBox6.Text
    If myName = "Sandy" Then myCol = "W"
    If myName = "Kim" Then myCol = "X"
    Range("V" & lr).Value = iDate

    Range(myCol & lr).Value = ComboBox10.Value



    'Sort Labor Costs
    Sheets(Sheet).Range("V2:X53").Sort key1:=Range("V2"), order1:=xlAscending, Header:=xlYes



    'Clear Form
    ComboBox6.Text = ""
    ComboBox10.Text = ""

    End Sub

    'Bank Deposits

    Private Sub CommandButton4_Click()
    Dim lr As Long
    Application.ScreenUpdating = True
    Sheet = ComboBox7.Text
    If Sheet = "" Then
    MsgBox "Select Month", vbInformation, "Error"
    Exit Sub
    End If
    Sheets(Sheet).Select
    Set findBlank = Range("AK2:AK53").Find(What:="", lookat:=xlWhole)
    findBlank.Select
    ActiveCell.Value = DTPicker4.Value
    ActiveCell.Offset(0, 1).Value = TextBox9.Text

    'Sort Bank Deposits
    Sheets(Sheet).Range("AK2:AL53").Sort key1:=Range("AK2"), order1:=xlAscending, Header:=xlYes


    'Clear Form
    ComboBox7.Text = ""
    TextBox9.Text = ""

    End Sub

    'Product Loss

    Private Sub CommandButton5_Click()
    Dim lr As Long
    Application.ScreenUpdating = True
    Sheet = ComboBox8.Text
    If Sheet = "" Then
    MsgBox "Select Month", vbInformation, "Error"
    Exit Sub
    End If
    Sheets(Sheet).Select
    Set findBlank = Range("AC2:AC53").Find(What:="", lookat:=xlWhole)
    findBlank.Select
    ActiveCell.Value = DTPicker5.Value
    ActiveCell.Offset(0, 1).Value = TextBox10.Text
    ActiveCell.Offset(0, 2).Value = ComboBox11.Text

    'Sort Product Loss

    Sheets(Sheet).Range("AC2:AE53").Sort key1:=Range("AC2"), order1:=xlAscending, Header:=xlYes

    'Clear Form
    TextBox10.Text = ""
    ComboBox11.Text = ""
    End Sub

    'Wendy Sales

    Private Sub CommandButton6_Click()
    Dim lr As Long
    Application.ScreenUpdating = True
    Sheet = ComboBox9.Text
    If Sheet = "" Then
    MsgBox "Select Month", vbInformation, "Error"
    Exit Sub
    End If
    Sheets(Sheet).Select
    Set findBlank = Range("AH2:AH53").Find(What:="", lookat:=xlWhole)
    findBlank.Select
    ActiveCell.Value = DTPicker6.Value
    ActiveCell.Offset(0, 1).Value = TextBox12.Text

    'Sort Wendy Sales
    Sheets(Sheet).Range("AH2:AI53").Sort key1:=Range("AH2"), order1:=xlAscending, Header:=xlYes

    'Clear Form
    TextBox12.Text = ""



    End Sub

    Private Sub CommandButton7_Click()
    Unload Entryform1
    End Sub

    Private Sub CommandButton8_Click()
    Dim lr As Long
    Application.ScreenUpdating = True
    Sheets("NEW EQUIP REPAIRS").Select
    Set findBlank = Range("A2:a20").Find(What:="", lookat:=xlWhole)
    findBlank.Select
    ActiveCell.Value = DTPicker7.Value
    ActiveCell.Offset(0, 1).Value = TextBox14.Text


    Sheets("NEW EQUIP REPAIRS").Range("A3:J20").Sort key1:=Range("A3"), order1:=xlAscending, Header:=xlYes

    End Sub

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,855

    Re: Using Date picker in Visual Basic with a Userform

    Firstly,
    Welcome to the Forum. It is important that you read and understand the rules of this forum if you expect to get any help.

    1. Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)

    2. Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important.

    (Note: this requirement is not optional. No help to be offered until the link is provided.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,302

    Re: Using Date picker in Visual Basic with a Userform

    As well as conforming to the above moderation please upload your workbook, it is evident from the posting you would benifit from more guidance as to loading comboboxes.
    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  4. #4
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: Using Date picker in Visual Basic with a Userform

    Quote Originally Posted by torachan View Post
    ...it is evident from the posting you would benifit from more guidance as to loading comboboxes.
    I already touched on this in the cross-posted thread.

+ 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] Excel-Visual Basic UserForm Coding
    By MrDrProfessorKing in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-03-2017, 11:17 PM
  2. Date picker UserForm to stay always in front of the main UserForm
    By Gabor in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-11-2014, 07:31 AM
  3. UserForm with Visual Basic Editor not opening
    By gsandy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-12-2010, 02:44 PM
  4. xls visual basic combobox date display help
    By somefred in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-22-2006, 03:17 PM
  5. [SOLVED] Coding Today's Date In Visual Basic
    By lj in forum Excel General
    Replies: 5
    Last Post: 08-07-2006, 02:05 PM
  6. [SOLVED] Can I run Visual Basic procedure using Excel Visual Basic editor?
    By john.jacobs71 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-26-2005, 10:25 AM
  7. Replies: 1
    Last Post: 09-13-2005, 07:06 AM

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