0

This simple line of code is throwing up error:

Application or Object defined error.

Sub vartest()
movie_name = "TITANIC"
Worksheets("Sheet1").Activate

Range("b1").End(xlDown).Offset(1, 0).Select
Active.Value = movie_name
MsgBox movie_name & " is the Movie"

Please help.

2 Answers 2

4

'Active' is not an acceptable object...

You would need something like ActiveCell

ActiveCell.Value = movie_name

Though you may be better off not selecting at all :

Sub vartest()
    movie_name = "TITANIC"
    Worksheets("Sheet1").Range("b1").End(xlDown).Offset(1, 0).Value = movie_name
    MsgBox movie_name & " is the Movie"
End Sub
Sign up to request clarification or add additional context in comments.

Comments

2

You need to change select and activate:

Sub vartest()

 Dim movie_name As String: movie_name = "TITANIC"
 Worksheets("Sheet1").Activate

 Range("b1").End(xlDown).Offset(1, 0).Activate
 Selection.Value = movie_name
 MsgBox movie_name & " is the movie"

End Sub

But try too avoid activate and select as already recommended. It slows down your code and it is not needed in most cases.

Comments

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.