+ Reply to Thread
Results 1 to 3 of 3

Date Button

  1. #1
    Forum Contributor
    Join Date
    04-25-2006
    Posts
    215

    Date Button

    I need a button that when pressed inserts today's date in a specific cell - only if its less than today's date or blank. If its already today's date, then do nothing. I have the following code that I've used to insert the date upon opening a workbook, but I can't seem to get it to work attached to a button..

    Private Sub Workbook_Open()
    Dim cell As Range
    Set cell = Worksheets("Sheet1").Range("A1")
    If cell.Text = "" Then
    cell.Value = Date
    End If
    End Sub

    Thanks.

  2. #2
    Bob Phillips
    Guest

    Re: Date Button

    Get a button from the Forms toolbar, and when you put it on the worksheet it
    asks to assign a macro, so assign this one

    Sub CheckDate()
    With Activecell
    If .Text = "" Or .Value < Date Then
    .Value = Date
    End If
    End With
    End Sub


    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "edwardpestian" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > I need a button that when pressed inserts today's date in a specific
    > cell - only if its less than today's date or blank. If its already
    > today's date, then do nothing. I have the following code that I've used
    > to insert the date upon opening a workbook, but I can't seem to get it
    > to work attached to a button..
    >
    > Private Sub Workbook_Open()
    > Dim cell As Range
    > Set cell = Worksheets("Sheet1").Range("A1")
    > If cell.Text = "" Then
    > cell.Value = Date
    > End If
    > End Sub
    >
    > Thanks.
    >
    >
    > --
    > edwardpestian
    > ------------------------------------------------------------------------
    > edwardpestian's Profile:

    http://www.excelforum.com/member.php...o&userid=33809
    > View this thread: http://www.excelforum.com/showthread...hreadid=556384
    >




  3. #3
    Forum Contributor
    Join Date
    04-25-2006
    Posts
    215
    Modified it to set the date in a specific cell.

    Thanks Bob

    Sub CheckDate()
    With Range("C10")
    If .Text = "" Or .Value < Date Then
    .Value = Date
    End If
    End With
    End Sub

+ 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