+ Reply to Thread
Results 1 to 6 of 6

Insert/append todays date when workbook is open

Hybrid View

  1. #1
    Registered User
    Join Date
    04-20-2008
    Location
    New York City
    MS-Off Ver
    2003
    Posts
    38

    Insert/append todays date when workbook is open

    Hello. I have a sheet with Dates going down column A. What I am trying to do is have todays date populate the next empty cell going down column A once the workbook is open. If todays date is present then do nothing.

    Private Sub Book_Date()
    
    ActiveWorkbook.Sheets("MySheet").Activate
    
        Range("A21").Select
    
        Do
    
        If IsEmpty(ActiveCell) = False Then
    
            ActiveCell.Offset(1, 0).Select
    
        End If
    
        Loop Until IsEmpty(ActiveCell) = True
    
        If Range("A21") = "" Then
           Range("A21") = Now
        End If
    
        Range("A21").Select
    
    End Sub
    I really dont know what I am doing. But I am trying. Thanks in advance.

  2. #2
    Registered User
    Join Date
    03-24-2010
    Location
    Pune, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    36

    Lightbulb Re: Insert/append todays date when workbook is open

    Hi evenings,

    As per my understanding about your query, you wish to add today's date in the lastrow of column A which is empty, right?

    If I guessed it right then you can try this code

    Private Sub Book_Date()
        Dim MaxRow As Integer
        ActiveWorkbook.Sheets("Sheet1").Activate
        'Range("A21").Select
        With ActiveWorkbook.Sheets("Sheet1")
            MaxRow = .Range("A1").End(xlDown).Row + 1
            .Cells(MaxRow, 1) = Now
        End With
    End Sub
    Cheerz,
    ~Ne@l

    *********************************************************************
    Save a tree. Please think before you print this post and/or attachments.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Insert/append todays date when workbook is open

    Hi,

    Assuming the dates are in chronological order then in the Workbook Open Event simply add

    If MySheet.Range("A" & Rows.Count).End(xlUp) <> Date Then MySheet.Range("A" & Rows.Count).End(xlUp) = Date
    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Insert/append todays date when workbook is open

    @nchavan: Using Now will add not only the current date, but also current time. Also if column A is empty it will leave Cell A1 blank.
    @ Richard: In this case it will overwright the last cell in column A.

    So I would suggest to add In ThisWorkbook module:

    Private Sub Workbook_Open()
        Dim cl As Range
    
        Worksheets(1).Activate
        Set cl = Cells(Rows.Count, 1).End(xlUp)
    
        If IsEmpty(cl) Then    'No entries in Column A
            cl = Date
        ElseIf cl <> Date Then
            cl.Offset(1, 0) = Date
        End If
    
        Set cl=Nothing
    
    End Sub
    Buran
    Last edited by buran; 03-29-2010 at 09:44 AM.
    If you are pleased with a member's answer then use the Star icon to rate it.

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Insert/append todays date when workbook is open

    @ Richard: In this case it will overwright the last cell in column A.

    Quite correct, well spotted. I should have added a .Offset. i.e.

    If MySheet.Range("A" & Rows.Count).End(xlUp) <> Date Then MySheet.Range("A" & Rows.Count).End(xlUp).Offset(1,0) = Date
    Rgds

  6. #6
    Registered User
    Join Date
    04-20-2008
    Location
    New York City
    MS-Off Ver
    2003
    Posts
    38

    Re: Insert/append todays date when workbook is open

    Thanks alot with the quick help guys. Subs are working great. thanks again

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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