+ Reply to Thread
Results 1 to 5 of 5

macro for filling in dates

  1. #1
    J_J
    Guest

    macro for filling in dates

    Hi experts,
    I have a small macro problem here I need to solve but can't seem to find my
    way out.
    Here is the problem: On Sheet1 column A:A I need to write down names and
    when I press enter after inputting the info, I want my macro to check if
    column "I" on the same row is empty and if so fill in that days date (in the
    "dd.mm.yyyy" format) to this cell on column "I", same row. But if there is
    already a date there, the macro should ask me if I want to change that date
    or not before doing so.
    Is it a simple task?.
    TIA
    J_J



  2. #2
    Carim
    Guest

    Re: macro for filling in dates

    Hi,

    take a look at Jim's brilliant solution :
    http://www.mcgimpsey.com/excel/timestamp.html

    HTH
    Carim


  3. #3
    Bob Phillips
    Guest

    Re: macro for filling in dates

    '-----------------------------------------------------------------
    Private Sub Worksheet_Change(ByVal Target As Range)
    '-----------------------------------------------------------------
    Const WS_RANGE As String = "A:A"

    On Error GoTo ws_exit:
    Application.EnableEvents = False
    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    With Target
    If .Offset(0, 8).Value <> "" Then
    If MsgBox("Overwrite existing date?", vbYesNo) = vbYes Then
    .Offset(0, 8).Value = Format(Date, "dd.mm.yyyy")
    End If
    Else
    .Offset(0, 8).Value = Format(Date, "dd.mm.yyyy")
    End If
    End With
    End If

    ws_exit:
    Application.EnableEvents = True
    End Sub

    'This is worksheet event code, which means that it needs to be
    'placed in the appropriate worksheet code module, not a standard
    'code module. To do this, right-click on the sheet tab, select
    'the View Code option from the menu, and paste the code in.




    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "J_J" <[email protected]> wrote in message
    news:[email protected]...
    > Hi experts,
    > I have a small macro problem here I need to solve but can't seem to find

    my
    > way out.
    > Here is the problem: On Sheet1 column A:A I need to write down names and
    > when I press enter after inputting the info, I want my macro to check if
    > column "I" on the same row is empty and if so fill in that days date (in

    the
    > "dd.mm.yyyy" format) to this cell on column "I", same row. But if there is
    > already a date there, the macro should ask me if I want to change that

    date
    > or not before doing so.
    > Is it a simple task?.
    > TIA
    > J_J
    >
    >




  4. #4
    Don Guillett
    Guest

    Re: macro for filling in dates

    right click sheet tab>view code>insert this

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim dc As Range
    If Target.Row < 2 And Target.Column <> 1 Then Exit Sub
    Set dc = Cells(Target.Row, "I")
    Application.EnableEvents = False
    If Not IsDate(dc) Then
    dc = Date
    Else
    nd = InputBox("Change date or cancel")
    If nd = "" Then
    Application.EnableEvents = True
    Exit Sub
    Else
    dc = nd
    End If
    End If
    Application.EnableEvents = True
    End Sub

    --
    Don Guillett
    SalesAid Software
    [email protected]
    "J_J" <[email protected]> wrote in message
    news:[email protected]...
    > Hi experts,
    > I have a small macro problem here I need to solve but can't seem to find
    > my way out.
    > Here is the problem: On Sheet1 column A:A I need to write down names and
    > when I press enter after inputting the info, I want my macro to check if
    > column "I" on the same row is empty and if so fill in that days date (in
    > the "dd.mm.yyyy" format) to this cell on column "I", same row. But if
    > there is already a date there, the macro should ask me if I want to change
    > that date or not before doing so.
    > Is it a simple task?.
    > TIA
    > J_J
    >
    >




  5. #5
    J_J
    Guest

    Re: macro for filling in dates

    Thank you all...
    I'll give them all a try.
    J_J

    "Don Guillett" <[email protected]> wrote in message
    news:[email protected]...
    > right click sheet tab>view code>insert this
    >
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > Dim dc As Range
    > If Target.Row < 2 And Target.Column <> 1 Then Exit Sub
    > Set dc = Cells(Target.Row, "I")
    > Application.EnableEvents = False
    > If Not IsDate(dc) Then
    > dc = Date
    > Else
    > nd = InputBox("Change date or cancel")
    > If nd = "" Then
    > Application.EnableEvents = True
    > Exit Sub
    > Else
    > dc = nd
    > End If
    > End If
    > Application.EnableEvents = True
    > End Sub
    >
    > --
    > Don Guillett
    > SalesAid Software
    > [email protected]
    > "J_J" <[email protected]> wrote in message
    > news:[email protected]...
    >> Hi experts,
    >> I have a small macro problem here I need to solve but can't seem to find
    >> my way out.
    >> Here is the problem: On Sheet1 column A:A I need to write down names and
    >> when I press enter after inputting the info, I want my macro to check if
    >> column "I" on the same row is empty and if so fill in that days date (in
    >> the "dd.mm.yyyy" format) to this cell on column "I", same row. But if
    >> there is already a date there, the macro should ask me if I want to
    >> change that date or not before doing so.
    >> Is it a simple task?.
    >> TIA
    >> J_J
    >>
    >>

    >
    >




+ 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