Nicki
Nicki

Reputation: 11

VBA 2015 "shape" Type undefined

I'm still somewhat new to VBA and I am having trouble defining an object as a shape. I have an excel worksheet with a rectangle and I would like to change the color of this shape from a comboBox in my VBA User Form. I have tried the code bellow and several other methods however I keep running into the error that "shape" is not a type, and this prevents me from using members such as fill. It might help to know I am using VBA 2015 as I know there are some differences between years

Dim rectangle as Shape
rectangle = sheet1.shapes("rectangle 1")
rectangle.Fill.Forecolor.RGB = RGB(255, 255, 255)

Upvotes: 0

Views: 398

Answers (2)

Gordon Bell
Gordon Bell

Reputation: 13633

Run this to list shapes on Sheet1. Are you sure you have a "Rectangle 1"?

Sub ListShapes()
    For Each s In Sheets("Sheet1").Shapes
        MsgBox s.Name
    Next
End Sub

Upvotes: 0

Gordon Bell
Gordon Bell

Reputation: 13633

Does this work?

With sheet1.shapes("rectangle 1")
    .Fill.Forecolor.RGB = RGB(255, 255, 255)
End With

Upvotes: 0

Related Questions