Dynamically create formula for shapes VBA

The_Steward

Board Regular
Joined
Nov 26, 2020
Messages
63
Office Version
  1. 365
Platform
  1. Windows
Hey!

Trying get this code to work:
VBA Code:
shapes.OLEFormat.Object.Formula = namesheet.Cells(names, 10)


Error Code says it can't set formula property of rectangle.

I am trying to get shapes I created to in another part of macro to dynamically change their textframe when the cell they correspond with is changed.

Any help really appreciated.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try the following . . .

VBA Code:
shapes.DrawingObject.Formula = "=" & namesheet.Cells(names, 10).Address(external:=True)

Note, however, naming your variable shapes can be a bit confusing. First, Excel contains a Shapes collection. Secondly, shapes suggests more than one shape. Therefore, try naming your variable something else. Actually, since you're creating shapes within a loop, you could name your variable something like currentShape as an example.

Hope this helps!
 
Upvote 0
Solution
Try the following . . .

VBA Code:
shapes.DrawingObject.Formula = "=" & namesheet.Cells(names, 10).Address(external:=True)

Note, however, naming your variable shapes can be a bit confusing. First, Excel contains a Shapes collection. Secondly, shapes suggests more than one shape. Therefore, try naming your variable something else. Actually, since you're creating shapes within a loop, you could name your variable something like currentShape as an example.

Hope this helps!
Worked perfectly! Thankyou!
 
Upvote 0

Forum statistics

Threads
1,223,939
Messages
6,175,533
Members
452,652
Latest member
eduedu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top