user3504930
user3504930

Reputation: 3

VBA Error Compile: Expected: Expression

I am working on some homework and I can't figure out why my code won't work. The assignment is to request a name then respond in red text in B10.

Here is my code:

enter image description here

Any help would be great- Thanks!

Upvotes: 0

Views: 7025

Answers (2)

Roger Barreto
Roger Barreto

Reputation: 2284

This error comes from the line With RAnge("b10").Font.ColocarIndex = 3, With supose to be used only to objects (not expressions)

sName = Application.InputBox(Prompt:="Please enter your name.", Type:=2)    
With Sheets("MyNewSheet").Range("B10")
    .Font.ColorIndex = 3
    .Value = sName 
End With

Upvotes: 1

Gary's Student
Gary's Student

Reputation: 96753

Consider:

Sub qwerty()
    Sheets("MyNewSheet").Activate
    With Range("B10")
        .Font.ColorIndex = 3
        strName = Application.InputBox(Prompt:="Please enter your name.", Type:=2)
        .Value = strName
    End With
End Sub

Upvotes: 0

Related Questions