1

I am writing an Excel Macro to display a warning if the user edits a cell that was previously empty. Basically if a cell is edited, is in column 1, and already contains text I want to display a warning But if it does not have text already, I do not want to.

So what I have tried is the following

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 1 And Not IsEmpty(Cells(Target.Row,Target.Column)) Then
        Application.EnableEvents = False
        MsgBox "Some Message"
        Application.EnableEvents = True
    End If
End Sub

The issue I am having is when I am getting the cell to see if it was empty or not, it will never return that it was because, well the user just added stuff to it.

So I want to know if there is a simple way to check the previous state of that cell. I want to find out if the cell WAS empty. Is this possible?

2
  • 1
    stackoverflow.com/questions/4668410/… Commented Sep 12, 2013 at 14:21
  • @mr.Reband Thanks for that, I tried searching for a question on here but I guess I was not using the proper search terms. Commented Sep 12, 2013 at 14:49

1 Answer 1

4

You could use the Worksheet_SelectionChange event to capture the value of the cell that the user has selected in a variable, which happens before they make any changes.

Then when Worksheet_Change is fired, you can refer to that variable.

Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I ended up doing, and was based off of the comment that mr.Reband posted as a comment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.