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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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,215,372
Messages
6,124,531
Members
449,169
Latest member
mm424

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