Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8466719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:25:29+00:00 2026-06-10T15:25:29+00:00

This is a universal log system, that a few people here and myself have

  • 0

This is a universal log system, that a few people here and myself have created. I’m rather proud of it… I am running into two issues… if someone can help with the sollution it be great.

Here is the code:

Option Explicit
Dim PreviousValue

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim sLogFileName As String, nFileNum As Long, sLogMessage As String

    sLogFileName = ThisWorkbook.path & Application.PathSeparator & "Log.txt"

 On Error Resume Next ' Turn on error handling
    If Target.Value <> PreviousValue Then
        ' Check if we have an error
        If Err.Number = 13 Then
           PreviousValue = 0
        End If
        ' Turn off error handling
        On Error GoTo 0
        sLogMessage = Now & Application.UserName & " changed cell " & Target.Address _
        & " from " & PreviousValue & " to " & Target.Value

        nFileNum = FreeFile                         ' next file number
        Open sLogFileName For Append As #nFileNum   ' create the file if it doesn't exist
        Print #nFileNum, sLogMessage                ' append information
        Close #nFileNum                             ' close the file
    End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    PreviousValue = Target(1).Value
End Sub

Here are the two issues.

  1. If more than once cell is selected, and attempted to be written to, the script errors out.
  2. If someone edits a cell and leaves it blank, it will show 8/30/2012 1:45:01 PM Matthew Ridge changed cell $K$3 from Test to instead of 8/30/2012 1:45:01 PM Matthew Ridge changed cell $K$3 from Test to Blank or Empty
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:25:31+00:00Added an answer on June 10, 2026 at 3:25 pm

    Matt

    Few Things

    1. On Error Resume Next is not proper handling. It should be avoided unless and until it is absolutely necessary.
    2. When you are working with Worksheet_Change event, it is better to switch off events and then turn them back on at the end to avoid possible endless loop.
    3. If you are switching events off then it is a must that you use proper error handling.
    4. Since you are storing the just a single cell in the PreviousValue so I am assuming that you do not want the code to run when the user selects multiple cells?

    I think this is what you are trying (UNTESTED)?

    Option Explicit
    
    Dim PreviousValue
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim sLogFileName As String, nFileNum As Long, sLogMessage As String
        Dim NewVal
    
        On Error GoTo Whoa
    
        Application.EnableEvents = False
    
        sLogFileName = ThisWorkbook.Path & Application.PathSeparator & "Log.txt"
    
        If Not Target.Cells.Count > 1 Then
            If Target.Value <> PreviousValue Then
                If Len(Trim(Target.Value)) = 0 Then _
                NewVal = "Blank" Else NewVal = Target.Value
    
                sLogMessage = Now & Application.UserName & _
                " changed cell " & Target.Address & " from " & _
                PreviousValue & " to " & NewVal
    
                nFileNum = FreeFile
                Open sLogFileName For Append As #nFileNum
                Print #nFileNum, sLogMessage
                Close #nFileNum
            End If
        End If
    LetsContinue:
        Application.EnableEvents = True
        Exit Sub
    Whoa:
        MsgBox Err.Description
        Resume LetsContinue
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        PreviousValue = Target(1).Value
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that needs to create a text log. In XP, everything
I have a very, very weird effect here using Monotouch 5.2.5 running my app
I have an universal application that plays movies from the internet. It has to
I'm out in the woods with this one: I have a universal, navigation-based app
I have a universal app but this issue seems to only relate to the
I have the following code for my universal app but I'm getting this weird
I have a universal app that displays buttons inside an actionsheet. UIActionSheet *actionSheet =
this is my first question in here, and I would like to ask if
This should be a simple one: I have an observableArray object called To in
I have a Universal app which is targeting 10.5 and which uses garbage collection.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.