Meysam
Meysam

Reputation: 18137

Why am I getting Object Required error (VBA, Excel)

Why is the following code wrong?

Sub SetFont()
    Dim a1 As Range
    Set a1 = Range("a1")
    SetFontSize (a1)
End Sub

Sub SetFontSize(target As Range)
    target.Font.Size = 11
End Sub

I am getting "Run-time error 424: Object required" error when calling the SetFontSize method.

Upvotes: 1

Views: 1940

Answers (1)

You're not calling a function, you don't need the parentheses when calling SetFontSize (a1).

Just use:

SetFontSize a1

Upvotes: 4

Related Questions