Home > Software engineering >  Adding a note with VBA throws "Object variable or With block variable not set"
Adding a note with VBA throws "Object variable or With block variable not set"

Time:11-26

I have a created this macro with the Record Macro function of Excel:

Sub Macro1()
    Range("J2").Select
    Range("J2").AddComment
    Range("J2").Comment.Visible = False
    Range("J2").Comment.Text Text:="qsd"
    Range("L8").Select
End Sub

When running the sub function created like this:

Sub test()
    Call Macro1
End Sub

I get this error: "Object variable or With block variable not set".

The error is on line 3 according to the debugger: enter image description here

CodePudding user response:

The problem was indeed that there was already a comment.

  • Related