FredMcStaire
New Member
- Joined
- Jan 19, 2009
- Messages
- 36
I have the following code that loops through a list and for each item in the list creates a shape with the text equal to the list item. . It works fine, but need some help to augment by changing two things:
1) instead of just putting the text in as a static item, how do i put in a formula ?
2) the active region is causing a few issues: the cursor needs to be at the start of the list, and "currentregion" picks up cells around the list.
Thanks!
1) instead of just putting the text in as a static item, how do i put in a formula ?
2) the active region is causing a few issues: the cursor needs to be at the start of the list, and "currentregion" picks up cells around the list.
Thanks!
VBA Code:
Sub ListToShapesWithText()
' to create as many shapes as there are rows in a list and then populate the shapes with the text in the cells
Dim NumberOfRows As Long
Dim CurrentName As String
Dim PositionX As Integer ' to offset a bit on the x axis
Dim PositionY As Integer ' to offset a bit on the y axis
NumberOfRows = Selection.CurrentRegion.Rows.Count
For i = 1 To NumberOfRows ' to start the loop
'to find the current name
CurrentName = ActiveCell.Value
'to set the placement of the shape
PositionX = 500 + (i * 10)
PositionY = 200 + (i * 10)
'to add the shape in a certain spot, all slightly offset
ActiveSheet.Shapes.AddShape(msoShapeRoundedRectangle, PositionX, PositionY, 100, 30).Select
'to style the shape
Selection.ShapeRange.ShapeStyle = msoShapeStylePreset6
'to name the current shape
Selection.Name = CurrentName
'to put text into the shape
ActiveSheet.Shapes(CurrentName).TextFrame.Characters.Text = CurrentName
'to move the selection down one
ActiveCell.Offset(1, 0).Select
Next i
End Sub
Last edited: