Consulting

Results 1 to 7 of 7

Thread: Solved: Code to automatically enter data update date

  1. #1
    VBAX Tutor
    Joined
    Feb 2008
    Location
    New York
    Posts
    215
    Location

    Solved: Code to automatically enter data update date

    Hi all,

    I have the following code to enter data update date. Lately, this code works only when I first open the workbook and type something, after sometime, the code doesn't enter date, but when I close and reopen the file and enter something, then it works again. Can someone tell me what's needs to be changed. Is it because it is conflicting with other codes? Thanks.

    [VBA]Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rg As Range, rgRow As Range
    On Error GoTo ExitHere
    Set rg = Range("a1:b100")
    If Intersect(rg, Target) Is Nothing Then Exit Sub
    Application.EnableEvents = False
    For Each rgRow In Intersect(Target, rg).Rows
    Cells(rgRow.Row, "c") = Date
    Next rgRow
    ExitHere:
    Application.EnableEvents = True
    End Sub[/VBA]
    -u

  2. #2
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    Do you have any other code anywhere in the VB project that toggles EnableEvents to False?
    Regards,

    Patrick

    I wept for myself because I had no PivotTable.

    Then I met a man who had no AutoFilter.

    Microsoft MVP for Excel, 2007 & 2008

  3. #3
    VBAX Tutor
    Joined
    Feb 2008
    Location
    New York
    Posts
    215
    Location
    I might have set enable events to false at the beginning of the code to speed up the macro, should I turn it on?
    -u

  4. #4
    VBAX Tutor
    Joined
    Feb 2008
    Location
    New York
    Posts
    215
    Location
    I also noticed that some other macros also stops working after sometime and that for most of the macros I have used to make the macros run faster, what should I do?
    [VBA]
    Sub .... ()
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    'My macros
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    End Sub
    [/VBA]
    -u

  5. #5
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    Quote Originally Posted by U_Shrestha
    I might have set enable events to false at the beginning of the code to speed up the macro, should I turn it on?
    Not necessarily--sometimes it's necessary to avoid a cascade of events.

    My guess is that there must be a placed where EnableEvents has been turned off and never reset.
    Regards,

    Patrick

    I wept for myself because I had no PivotTable.

    Then I met a man who had no AutoFilter.

    Microsoft MVP for Excel, 2007 & 2008

  6. #6
    VBAX Tutor
    Joined
    Feb 2008
    Location
    New York
    Posts
    215
    Location
    Hello Patrick,

    I found one place where it wasn't turned back on and the macros are working so far. However, I will wait till end of day to mark it solved. Thanks for your help
    -u

  7. #7
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    Glad to help
    Regards,

    Patrick

    I wept for myself because I had no PivotTable.

    Then I met a man who had no AutoFilter.

    Microsoft MVP for Excel, 2007 & 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •