placing the date from the last row of a column into a Textbox in the Userform

  • I am pretty new to VBA (and self learning) and I apologize if this has been asked, but I have been through countless of posts, pages and videos for 2 days and I can't get this to work.


    forum.ozgrid.com/index.php?attachment/69157/
    My workbook is called LYFT log


    There is a (2) command button(s) that launch a userform, "cmdLaunchMileageLog" and the yet to be renamed "CommandButton1"
    I have a worksheet named "Mileage"
    I have a userform named "frmMileage"
    In the userform there is a text box named txtLastEntry


    I would like txtLastEntry to display the last data cell entered in column A (a date) of worksheet Mileage when the userform is launched, so that the userform user doesn't have to go to the actual worksheet to know where they left off.


    I have tried every code I have found and nothing seems to work. Can someone help me please?


    Thanks so much.

  • Re: placing the date from the last row of a column into a Textbox in the Userform


    Hi oren76,


    Comment out (or delete) the txtLastEntry_Change code and then put this at the top of that code page:


    Code
    Private Sub UserForm_Initialize()    'Note the reference 'Mileage' is actually the code name of the tab, not the worksheet name
        Me.txtLastEntry = Format(Mileage.Range("A" & Mileage.Cells(Rows.Count, "A").End(xlUp).Row), "dd/mm/yyyy")
    End Sub


    Regards,


    Robert

  • Re: placing the date from the last row of a column into a Textbox in the Userform


    Robert,


    Thanks for the reply. I used your code and it did not exactly work.


    Upon launch of the userform textbox txtLastEntry has no information in it. But, once a new entry is made, txtLastEntry displays the data in whatever cell is mouse click higlighted. Not the last cell of column A and also not at initalization.

  • Re: placing the date from the last row of a column into a Textbox in the Userform


    Originally you said...


    Quote

    I would like txtLastEntry to display the last data cell entered in column A (a date) of worksheet Mileage when the userform is launched, so that the userform user doesn't have to go to the actual worksheet to know where they left off.


    ...now you say:


    Quote
    Quote

    Upon launch of the userform textbox txtLastEntry has no information in it. But, once a new entry is made, txtLastEntry displays the data in whatever cell is mouse click higlighted. Not the last cell of column A and also not at initalization.


    So which is it? The initialize event is executed when the form is "launched".


  • Re: placing the date from the last row of a column into a Textbox in the Userform


    Ah - I think I see what you're after. Try this as your MileageLog macro in Module1...



    ...and then comment (or delete) the txtLastEntry_Change code on the frmMileage from.


    Determining the active cell is one of the few VBA occasions where you have you have to select the relevant tab to return the value. Note though the cursor doesn't have to be in column A.


    Robert

  • Re: placing the date from the last row of a column into a Textbox in the Userform


    Thanks Robert for the ongoing help. Unfortunately that did not work.


    I tried your code in module1 and I also tried changing "sheet1.select" to "mileage.select" and neither worked.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!