+ Reply to Thread
Results 1 to 6 of 6

Conditional date stamp?

  1. #1
    Forum Contributor
    Join Date
    12-16-2004
    Posts
    125

    Conditional date stamp?

    I am looking for an event macro that will place a date in column B only when the letter "R" is placed in column A. Is this possible?

    Thanks for any replies.

  2. #2
    JE McGimpsey
    Guest

    Re: Conditional date stamp?

    Sure:

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    With Target
    If .Count > 1 Then Exit Sub
    If .Column = 1 Then
    If .Value = "R" Then
    With .Offset(0, 1)
    .NumberFormat = "dd mmm yyyy"
    Application.EnableEvents = False
    .Value = Date
    Application.EnableEvents = True
    End With
    End If
    End If
    End With
    End Sub


    If you want to include lowercase r's, substitute the line

    If UCase(.Value) = "R" Then

    In article <[email protected]>,
    CJ-22 <[email protected]> wrote:

    > I am looking for an event macro that will place a date in column B only
    > when the letter "R" is placed in column A. Is this possible?


  3. #3
    Forum Contributor
    Join Date
    12-16-2004
    Posts
    125
    Thanks JE McGimpsey, it works great. I have two additional questions.

    1) Can this be modified so that if I delete the "R" the date will also delete?

    2) Can this be modified to work in different columns if needed?

    Thanks again.

  4. #4
    JE McGimpsey
    Guest

    Re: Conditional date stamp?

    1)

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    With Target
    If .Count > 1 Then Exit Sub
    If Not Intersect(.Cells, Range("A:A")) Is Nothing Then
    Application.EnableEvents = False
    If .Value = "R" Then
    With .Offset(0, 1)
    .NumberFormat = "dd mmm yyyy"
    .Value = Date
    End With
    ElseIf Len(.Text) = 0 Then
    .Offset(0, 1).ClearContents
    End If
    Application.EnableEvents = True
    End If
    End With
    End Sub

    2) Change "A:A" to your desired columns, e.g.:

    If Not Intersect(.Cells, Range("J:J")) Is Nothing Then

    or

    If Not Intersect(.Cells, Range("A:A,J:J")) Is Nothing Then

    In article <[email protected]>,
    CJ-22 <[email protected]> wrote:

    > 1) Can this be modified so that if I delete the "R" the date will also
    > delete?
    >
    > 2) Can this be modified to work in different columns if needed?
    >
    > Thanks again.


  5. #5
    Forum Contributor
    Join Date
    12-16-2004
    Posts
    125
    Outstanding! That works great. Thanks so much JE McGimpsey.

  6. #6
    Bcastel
    Guest

    Re: Conditional date stamp?

    Would there be a way to add a date stamp to a saved file through a
    script? Such as <worksheetname>_<todaysdate>.xls?

    CJ-22 wrote:
    > I am looking for an event macro that will place a date in column B only
    > when the letter "R" is placed in column A. Is this possible?
    >
    > Thanks for any replies.
    >
    >


+ 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