ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Rectangle Size (https://www.excelbanter.com/excel-programming/390233-rectangle-size.html)

tiago

Rectangle Size
 
i'm adding to a rectangle a text from a range 1 by 1 character like this:

ActiveSheet.Shapes("Rectangle 3").Select
For i = 1 To Len(Range("J17"))
Selection.Characters.Text = Selection.Characters.Text +
Mid(Range("J17").Value, i, 1)
Next

It works, but when i arrives to 255 don't let me fill the rest of the
rectangle.

Anyone Help?
Thanks




Ken Johnson

Rectangle Size
 
You can use Characters' Start and Length parameters.

Try this...

Option Explicit
Public Sub test()
Dim lnInitialCharCount As Long, k As Long
With ActiveSheet.Shapes("Rectangle 3")
lnInitialCharCount = .TextFrame.Characters.Count
Do While Len(Range("J17").Value) - (k * 255 - 254) 0
k = k + 1
..TextFrame.Characters(Start:=lnInitialCharCount + k * 255 - 254, _
Length:=255).Text = Mid(Range("J17").Value, k * 255 - 254, 255)
Loop
End With
End Sub

Ken Johnson


tiago

Rectangle Size
 
it works

thanks Ken

"Ken Johnson" wrote:

You can use Characters' Start and Length parameters.

Try this...

Option Explicit
Public Sub test()
Dim lnInitialCharCount As Long, k As Long
With ActiveSheet.Shapes("Rectangle 3")
lnInitialCharCount = .TextFrame.Characters.Count
Do While Len(Range("J17").Value) - (k * 255 - 254) 0
k = k + 1
..TextFrame.Characters(Start:=lnInitialCharCount + k * 255 - 254, _
Length:=255).Text = Mid(Range("J17").Value, k * 255 - 254, 255)
Loop
End With
End Sub

Ken Johnson



Dave Peterson

Rectangle Size
 
Another one:

Option Explicit
Sub testme()
Dim myRect As Shape
Dim myCell As Range
Dim cCtr As Long

With Worksheets("sheet1")
Set myRect = .Shapes("rectangle 3")
Set myCell = .Range("J17")

For cCtr = 1 To Len(myCell.Text) Step 255
With myRect.TextFrame
.Characters(.Characters.Count + 1).Insert _
String:=Mid(myCell.Text, cCtr, 255)
End With
Next cCtr
End With
End Sub

Tiago wrote:

i'm adding to a rectangle a text from a range 1 by 1 character like this:

ActiveSheet.Shapes("Rectangle 3").Select
For i = 1 To Len(Range("J17"))
Selection.Characters.Text = Selection.Characters.Text +
Mid(Range("J17").Value, i, 1)
Next

It works, but when i arrives to 255 don't let me fill the rest of the
rectangle.

Anyone Help?
Thanks


--

Dave Peterson


All times are GMT +1. The time now is 08:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com