Bricklin
New Member
- Joined
- Nov 17, 2024
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
How do we revise VBA code for one item to apply to many? Sorry that I don't yet understand how to use the RANGE object.
Today I am struggling to apply VBA code to many shapes. I see how to create ONE shape based on cell values:
how-to-make-box-with-dimension.587948/#post-2908982
Likewise, we can change the shape of ONE existing shape.
But suppose we have a hundred shapes to manage. Dimensions of the first shape are in, say, row 3. Dimensions for the second shape are in row 4, and so forth to row 103.
How then do we connect the shapes with their rows? The code below links the properties of the first shape to the values in row 3. But all the other shapes are also wrongly linked to row 3. I can imagine how to fix this, but my approach would be tedious and error-prone.
Thanks
Today I am struggling to apply VBA code to many shapes. I see how to create ONE shape based on cell values:
how-to-make-box-with-dimension.587948/#post-2908982
Likewise, we can change the shape of ONE existing shape.
But suppose we have a hundred shapes to manage. Dimensions of the first shape are in, say, row 3. Dimensions for the second shape are in row 4, and so forth to row 103.
How then do we connect the shapes with their rows? The code below links the properties of the first shape to the values in row 3. But all the other shapes are also wrongly linked to row 3. I can imagine how to fix this, but my approach would be tedious and error-prone.
VBA Code:
Sub ChangeShapes()
Const X = "b3"
Const Y = "c3"
Const Z = "d3"
Const R = "e3"
Const Rx = "f3"
Const Ry = "g3"
Const Rz = "h3"
Dim mySheet As Worksheet
Dim myS As Shape
Set mySheet = activesheet
For Each myS In mySheet.Shapes
myS.Width = Range(X)
myS.Height = Range(Y)
myS.ThreeD.Depth = Range(Z)
myS.Rotation = Range(R)
myS.ThreeD.RotationX = Range(Rx)
myS.ThreeD.RotationY = Range(Ry)
myS.ThreeD.RotationZ = Range(Rz)
Next myS
End Sub
Thanks