+ Reply to Thread
Results 1 to 5 of 5

How to add date to cell, and if already present avoid inserting new date over the existing

  1. #1
    Registered User
    Join Date
    01-09-2013
    Location
    Houston Texas
    MS-Off Ver
    Excel 2010
    Posts
    9

    Talking How to add date to cell, and if already present avoid inserting new date over the existing

    Hello everyone thanks so much for this great site! This is like my 3rd post so far and I have gotten quick replies to the previous query in General category. Anyway this is the situation.

    I am in the quality department. The company uses excel spreadsheets for many things. On the company intranet there is a hyperlink to our QA web page which then links to another page with a html table listing created forms with a hyperlink to click to open the corresponding document. I have created a spreadsheet to allow other inspectors to add parts that need to be sent outside for coating processes. In the spreadsheet. To the right of a text label cell with the title "Date:" is of course an empty field. I would like to have the form update and insert the current date when opened from the hyperlink. However as part of this process I want to have it check to see if there is an existing date already there, and if so prompt the user to insert the current date. The idea here is to make sure the inspectors are actually getting the form off of the intratnet and not just opening an existing spreadsheet, clearing the contents and moving on. The forms have date and version control so as you can imagine we don't want to keep using a Rev. A document when changes were made and now it sits at Rev. B. A real problem if we are audited externally.

    I am not sure if a macro should be triggered when the file opens from the intranet, or if VB code should be used to achieve the goal of having a current date inserted, or prompting for date to be added in case of the date cell already containing a valid date.

    I hope my explanation has been concise.

    Thank you,

    Mel

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: How to add date to cell, and if already present avoid inserting new date over the exis

    You will have to add some code to the Workbook_Open event.

    For example, suppose the blank cell for entering data is A1 on Sheet1

    Public sub Workbook_Open()

    dim ws as Excel.Worksheet

    set ws = thisworkbook.worksheets("Sheet1")

    if ws.range("a1").value = "" then
    ws.range("a1").value = date
    else
    msgbox "Please enter current date in A1"
    ws.range("a1").select
    end if

    end sub

  3. #3
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: How to add date to cell, and if already present avoid inserting new date over the exis

    You will have to add some code to the Workbook_Open event.

    For example, suppose the blank cell for entering data is A1 on Sheet1

    Public sub Workbook_Open()

    dim ws as Excel.Worksheet

    set ws = thisworkbook.worksheets("Sheet1")

    if ws.range("a1").value = "" then
    ws.range("a1").value = date
    else
    msgbox "Please enter current date in A1"
    ws.range("a1").select
    end if

    end sub

  4. #4
    Registered User
    Join Date
    01-09-2013
    Location
    Houston Texas
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to add date to cell, and if already present avoid inserting new date over the exis

    Nathansav thanks so much! I will mark this question solved.

  5. #5
    Registered User
    Join Date
    01-09-2013
    Location
    Houston Texas
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to add date to cell, and if already present avoid inserting new date over the exis

    Nathansav I'm getting a subscript error and don't understand why. The cell is actually H1. I have changed your example to use h1 where appropriate. Stepping through the code under debug it throws the error at the "if ws.range("h1").value = "" I added the code by double clicking the sheet 1 reference in the VBAProject window. Can you assist?

    Public Sub Workbook_Open()

    Dim ws As Excel.Worksheet

    Set ws = ThisWorkbook.Worksheets("Sheet1")

    If ws.Range("h1").Value = "" Then
    ws.Range("h1").Value = Date
    Else
    MsgBox "Please enter current date in cell."
    ws.Range("h1").Select
    End If

    End Sub


    Thank You,

    Mel
    Last edited by Mel56; 01-09-2013 at 01:26 PM.

+ 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