+ Reply to Thread
Results 1 to 3 of 3

Change event - Inputing date into specific column

  1. #1
    Registered User
    Join Date
    05-14-2010
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 2003
    Posts
    8

    Question Change event - Inputing date into specific column

    I am working on a macro that will input the current date into a row in column "F" when any value in that row for columns "A" "B" and "C" is altered. It is so we can track changes to the database.

    it works so far with the following code:

    Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Cells.Count > 1 Then Exit Sub

    If Not Intersect(Target, Range("A2:b100")) Is Nothing Then

    With Target(1, 5)

    .Value = Date

    .EntireColumn.AutoFit

    End With

    End If

    End Sub


    the problem is obviously the "With Target(1, 5)" offsets too far if the value in B or C changes. I just need the date to be inputted into column F for the same row that is changed.

    any help would be appreciated!

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,454

    Re: Change event - Inputing date into specific column

    Hi and welcome,

    Please edit your post so that the code is between code tags - it makes it easier to read, and is required as part of the forum rules.

    Try this for your issue

    Please Login or Register  to view this content.
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Change event - Inputing date into specific column

    If you want to be able to update multiple rows simultaneously then you could use a version along the lines of:

    Please Login or Register  to view this content.
    It's always wise (IMO) to disable events when changing the sheet against which you have applied a Change event to avoid at best a needless event call or at worst a perpetual loop.

    The above is coded such that if the target is cleared then so too is the date (remove adapt as necessary).
    Last edited by DonkeyOte; 06-14-2010 at 12:40 PM. Reason: edit: amended re: non contiguous ranges

+ 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