1

I have this simple Event Macro, which for some reason throws me an

Object Required

error on this line If Not AppDate Is Nothing Then. Any idea what might be causing this?

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim LastRow As Integer
    Dim ThisRow As String
    Dim AppDate As Variant
    Application.EnableEvents = False

    LastRow = Cells(Rows.Count, "C").End(xlUp).Row
    If Target.Column = 3 Then
        ThisRow = Target.Row
        AppDate = Target.Value
        If Not AppDate Is Nothing Then
            (...) Recalculate Date in Column F
        Else
        End If
    End If

    Application.EnableEvents = True
End Sub

Any suggestions would be greatly appreciated. Thank you!

4
  • AppDate = new Target.Value Commented Nov 15, 2017 at 17:04
  • you can try Set AppDate = Target.Value (not tested) Commented Nov 15, 2017 at 17:07
  • @peakpeak I'm getting "User-defined type not defined" error... Commented Nov 15, 2017 at 17:09
  • @David -- a tutorial about Set. :-) I have a terriible memory and constantly make mistakes on my Nothings and Sets and such, so I end up cycling through the different syntaxes until it's right. Then it makes perfect sense... until the next time. Commented Nov 15, 2017 at 17:18

2 Answers 2

7

Is operator works with objects and not values.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim x As Variant
    Dim y As New Collection
    Dim z As Object

    x = Target.Value

    If IsEmpty(x) Then
        MsgBox "may be use this."
    End If

    MsgBox TypeName(x)

    If y Is Nothing Then
     MsgBox "Works"
    End If

    If z Is Nothing Then
     MsgBox "Works"
    End If

    If x Is Nothing Then '/This won't work

    End If


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

Comments

4

Use:

…
If Not IsEmpty(AppDate) 
…

To help clarify, here is a lengthy tutorial about Nothing. lol

2 Comments

You're welcome. This is reminding me of a Seinfeld episode... :)
Yep, writing something about nothing for so many pages requires some talent :)

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.