Hello!
I have created a spreadsheet on excel and a user form automatically pops up. The first entry is "Date". I was wondering if there is anyway to change my current code (see below) so that the current date is automatically entered on each new entry in order to save the user time.
Pleaseee help (:
Private Sub cmdAdd_Click() Dim iRow As Long Dim ws As Worksheet Set ws = Worksheets("Tasks") 'find first empty row in database iRow = ws.Cells(Rows.Count, 1) _ .End(xlUp).Offset(1, 0).Row 'copy the data to the database ws.Cells(iRow, 1).Value = Me.txtDate.Value ws.Cells(iRow, 2).Value = Me.cboTaskLead.Value ws.Cells(iRow, 3).Value = Me.txtTaskName.Value ws.Cells(iRow, 4).Value = Me.txtProject.Value ws.Cells(iRow, 5).Value = Me.txtTaskDescription.Value ws.Cells(iRow, 6).Value = Me.cboPriority1.Value ws.Cells(iRow, 7).Value = Me.cboPriority2.Value 'clear the data Me.txtDate.Value = "" Me.cboTaskLead.Value = "" Me.txtTaskName.Value = "" Me.txtTaskDescription.Value = "" Me.txtTaskDescription.Value = "" Me.cboPriority1.Value = "" Me.cboPriority2.Value = "" End Sub
You could try setting the object before you show the userform -
Dave HUserForm1.TextBox1 = Format(Now, "dd/mm/yyyy")
Sorry JessFace, bit hasty of me there, i shouldn't try multitasking.
Ignoremy previous post and add the following to the sub that shows your userform -
Dim Today_Dt As VariantToday_Dt = Format(Now, "dd/mm/yyyy")Sorry about thatUserForm1.TextBox1 = Today_Dt
Dave H
Hi Dave,
I am a bit confused as to wear to place those three lines of code that you gave me - I put them after this:
'find first empty row in database iRow = ws.Cells(Rows.Count, 1) _ .End(xlUp).Offset(1, 0).Row
Also, when I did put the code, the codewas highlighted and i got "Compile Error: User-defined type not defined" message.Today_Dt
Any idea if i need to change anything?
Nevermind,I realized i entered it in the wrong place and i tweaked your code just a bit and it worked.
Thanks a million!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks