Change the shape size based on the number of characters

blelli

Board Regular
Joined
Jul 21, 2013
Messages
73
Dears,

Supposing I have a rectangle shape... is it possible to change its X size based on a string's number of characters.

So, if it's a big text,it should be a big rectangle.

And how can I write this string's name into the rectangle?

Thank you
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
here you go.

you need to play with code and try changing high and width.

Code:
Sub Change_ShapeSize()
Dim Text_lenght As String
Dim oShape As Shape
Set oShape = Worksheets("Sheet3").Shapes("Rectangle 1")
With oShape
        Text_lenght = Len(.TextFrame2.TextRange.Characters.Text)
        
            Select Case Text_lenght
                Case 1 To 10
                    .Height = 50   ''' change number here
                    .Width = 150   '' change number here
                Case 11 To 20
                    .Height = 100   '' change number here
                    .Width = 250   '' change number here
                Case 21 To 30
                    .Height = 50   '' change number here
                    .Width = 300  '' change number here
                Case Else
                    .Height = 150  '' '' change number here
                    .Width = 150  '' change number here
                End Select
    End With
    oShape.TextFrame2.TextRange.Characters.Text = "This for testing..."    ''''' this line write text into shape.
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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