+ Reply to Thread
Results 1 to 10 of 10

how to add a date when opening up the worksheet

Hybrid View

dmcgov how to add a date when... 12-27-2016, 10:35 AM
Logit Re: how to add a date when... 12-27-2016, 11:08 AM
Richard Buttrey Re: how to add a date when... 12-27-2016, 12:15 PM
Winon Re: how to add a date when... 12-27-2016, 01:18 PM
dmcgov Re: how to add a date when... 12-28-2016, 08:15 AM
dmcgov Re: how to add a date when... 12-28-2016, 08:53 AM
dmcgov Re: how to add a date when... 12-28-2016, 08:49 AM
Winon Re: how to add a date when... 12-28-2016, 09:09 AM
dmcgov Re: how to add a date when... 12-28-2016, 09:28 AM
Logit Re: how to add a date when... 12-28-2016, 10:58 AM
  1. #1
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    how to add a date when opening up the worksheet

    so i have a worksheet "Production Timesheet Checklist" that has a field with a date in it.

    i need a macro that adds "7" to a date field ("B1"). Also need the macro to ask if the date should be updated.

    i guess i need the worksheet open function to make this work. not sure of what else i need to do.

    thoughts everyone?

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,400

    Re: how to add a date when opening up the worksheet

    Try this:

    Private Sub Worksheet_Activate()
        Range("B1").Value = 7
        MsgBox "Should the date be updated at this time ? "
    End Sub
    Attached Files Attached Files

  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: how to add a date when opening up the worksheet

    There's no 'worksheet' open event. Did you mean the 'workbook' open event, or perhaps the sheet Activate event?
    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 Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: how to add a date when opening up the worksheet

    Hello dmcgov,

    Please try this Code:

    Option Explicit
    
    Private Sub Worksheet_Activate()
        
        If MsgBox("Should the date be updated at this time ? ", vbCritical + vbYesNo, ("Confirmation Required")) = vbYes Then
        Range("B1").Value = Range("B1").Value + Range("G1").Value
        Else: Range("B1").Value = Range("B1").Value
        Exit Sub
        End If
    
    End Sub
    Attached Files Attached Files
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  5. #5
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to add a date when opening up the worksheet

    thanks logit and richard.

    winon, i like your code but i changed the "Range("G1").Value to 7 and now it works the way i was expecting it to. Thanks very much for your code. Gold stars all around.

  6. #6
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to add a date when opening up the worksheet

    so nevermind, i figured it out. just needed to source the range, like so:

    Private Sub Workbook_Open()
        
        If MsgBox("Should the date be updated at this time ? ", vbCritical + vbYesNo, ("Confirmation Required")) = vbYes Then
        Sheets("HWI").Range("B1").Value = Sheets("HWI").Range("B1").Value + 7
        Else: Range("B1").Value = Range("B1").Value
        Exit Sub
        End If
    
    End Sub

  7. #7
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to add a date when opening up the worksheet

    one question for winon, when i set the workbook_open in the ThisWorkbook, the macro fails on the B1 line. thoughts?

    Private Sub Workbook_Open()
        
        If MsgBox("Should the date be updated at this time ? ", vbCritical + vbYesNo, ("Confirmation Required")) = vbYes Then
        Range("B1").Value = Range("B1").Value + 7
        Else: Range("B1").Value = Range("B1").Value
        Exit Sub
        End If
    
    End Sub
    the error is "run time error 1004, method range of object _Global failed
    Last edited by dmcgov; 12-28-2016 at 08:50 AM. Reason: added error code

  8. #8
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: how to add a date when opening up the worksheet

    Thank you for the continued interest dmcgov,

    Very well done, you do me proud with your initiative! WOW!

    Instead of the Sheet Name you could also use the Sheet Index No. as shown in the Code below:

    Option Explicit
    
    Private Sub Workbook_Open()
     Sheet1.Activate
        If MsgBox("Should the date be updated at this time ? ", vbCritical + vbYesNo, ("Confirmation Required")) = vbYes Then
        Sheet1.Range("B1").Value = Sheet1.Range("B1").Value + Sheet1.Range("G1").Value
        Else: Sheet1.Range("B1").Value = Sheet1.Range("B1").Value
        End If
    
    End Sub
    Please note that the Exit Sub Line has been removed, since it is not required. you Can do the Same in the Sheet Code.

    You are welcome, glad I could help. Also thank you for the Rep, I appreciate it.!

    Kind Regards.

  9. #9
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to add a date when opening up the worksheet

    Thanks again Winon for all your help. Your the bomb!

  10. #10
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,400

    Re: how to add a date when opening up the worksheet

    Glad you got it worked out. Thanks for the add rep.


+ 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. Date picker used to populate text box. Date changes back to original value on opening.
    By Stratfordoaks in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-07-2016, 09:42 AM
  2. Replies: 4
    Last Post: 03-12-2014, 02:06 AM
  3. Replies: 4
    Last Post: 01-24-2012, 12:52 PM
  4. Replies: 6
    Last Post: 10-03-2011, 04:26 PM
  5. Upon opening the WorkSheet, how to check the date
    By alghareeb in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-29-2009, 08:52 AM
  6. Go to current date upon opening Worksheet
    By Jason in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-21-2006, 08:45 AM
  7. [SOLVED] Make date change in excel to current date when opening daily?
    By jamie in forum Excel General
    Replies: 3
    Last Post: 03-01-2006, 11:40 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