0
votes

I am building a userform that has the user input data and it will then transfer it to another sheet titled "Tracker." As part of the form, I am tagging all of the entries with the current date which I have in a textbox, but it will not appear until you run the form, click in the textbox and try to type something. Here is my code which will hopefully convey my project a little more clearly.

Private Sub CommandButton3_Click()
   Dim LastRow As Long, ws As Worksheet

    Set ws = Sheets("Tracker")
    Sheets("Tracker").Select
    LastRow = ws.range("A" & Rows.Count).End(xlUp).Row + 1 'Finds the last blank row
    ws.range("A" & LastRow).Value = date_txtb.Text 'Adds the TextBox3 into Col A & Last Blank Row
    ws.range("B" & LastRow).Value = ComboBox1.Text 'Adds the ComboBox1 into Col B & Last Blank Row


End Sub

Private Sub date_txtb_Change()
date_txtb.Text = Format(Now(), "MM/DD/YY")
End Sub

Command Button 3 transfers the data from the Userform to the "Tracker" sheet, and the sub below is the code for the textbox that is supposed to display the current date. What can I add or change to ensure that the date populates as soon as the form is initialized? Any help is appreciated, thanks!

1
So what is your question? You didn't ask one? Side note: LastRow = ws.range("A" & Rows.Count).End(xlUp).Row should be LastRow = ws.range("A" & ws.Rows.Count).End(xlUp).Row (note the ws. before Rows.Count). - Pᴇʜ
Updated post to hopefully make it more clear. I need the date to populate as soon as the form is initialized. - accortdr
How about using the Private Sub UserForm_Initialize() procedure in your userform? - Pᴇʜ
I have actually tried that and it did not work. Private Sub UserForm_Initialize() UserForm1.Show date_txtb.Text = Format(Now(), "MM/DD/YY") End Sub - accortdr
Then edit your question and show a detailed description of what you tried. Also "did not work" is never a good error description. Tell always what you expected your code should do and what it actually did. - Pᴇʜ

1 Answers

0
votes

Use a UserForm event, so when the userform is loaded, the date will be displayed.

Private Sub UserForm_Initialize()
     date_txtb.Text = Format(Now(), "MM/DD/YY")
End Sub