Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Combine cell contents into a text box

I have created an excel macro that takes the current selection of cell
and combines them using a string that I just add the value of each cell
to then I create a text box, and set the text box value to the string.
It seems to work great, until I select many cells to combine - I think
I am running into the 255 character limit on this one but don't know
how to get around it. My understanding is that strings can old a very
large number of characters so I don't know why I am running into this
issue. Any help would be much appreciated.

Here is my code:

Public Sub Combine_cells()

Dim r As Range
Set r = Selection

Dim c As Range

Dim $thestring
thestring = ""

'iterate through the selected cells to make the string
For Each c In r.Cells

If thestring = vbNullString Then
thestring = CStr(c.Value)
Else
thestring = thestring + " " + CStr(c.Value)
End If

Next c


'create the text box and put the string in it.
ActiveSheet.Shapes.AddTextbox(msoTextOrientationHo rizontal, 386.25,
134.25, _
288#, 90.75).Select

With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Selection.ShapeRange.Fill.Visible = msoTrue
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 43
Selection.ShapeRange.Fill.Transparency = 0#
Selection.ShapeRange.Line.Weight = 0.75
Selection.ShapeRange.Line.DashStyle = msoLineSolid
Selection.ShapeRange.Line.Style = msoLineSingle
Selection.ShapeRange.Line.Transparency = 0#
Selection.ShapeRange.Line.Visible = msoTrue
Selection.ShapeRange.Line.ForeColor.SchemeColor = 64
Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
Selection.Text = thestring

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Combine cell contents into a text box


Couple of things I see...

Dim $thestring
should be...
Dim theString$

thestring = thestring + " " + CStr(c.Value)
should be...
theString = theString & " " & CStr(c.Value)
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware




wrote in message
I have created an excel macro that takes the current selection of cell
and combines them using a string that I just add the value of each cell
to then I create a text box, and set the text box value to the string.
It seems to work great, until I select many cells to combine - I think
I am running into the 255 character limit on this one but don't know
how to get around it. My understanding is that strings can old a very
large number of characters so I don't know why I am running into this
issue. Any help would be much appreciated.

Here is my code:

Public Sub Combine_cells()

Dim r As Range
Set r = Selection

Dim c As Range

Dim $thestring
thestring = ""

'iterate through the selected cells to make the string
For Each c In r.Cells

If thestring = vbNullString Then
thestring = CStr(c.Value)
Else
thestring = thestring + " " + CStr(c.Value)
End If

Next c


'create the text box and put the string in it.
ActiveSheet.Shapes.AddTextbox(msoTextOrientationHo rizontal, 386.25,
134.25, _
288#, 90.75).Select

With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Selection.ShapeRange.Fill.Visible = msoTrue
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 43
Selection.ShapeRange.Fill.Transparency = 0#
Selection.ShapeRange.Line.Weight = 0.75
Selection.ShapeRange.Line.DashStyle = msoLineSolid
Selection.ShapeRange.Line.Style = msoLineSingle
Selection.ShapeRange.Line.Transparency = 0#
Selection.ShapeRange.Line.Visible = msoTrue
Selection.ShapeRange.Line.ForeColor.SchemeColor = 64
Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
Selection.Text = thestring

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I combine cell contents? Storm Excel Discussion (Misc queries) 1 April 13th 07 11:23 PM
Combining cell contents when there is content to combine Richard Excel Discussion (Misc queries) 2 June 21st 06 07:30 PM
how to combine text into a cell??? Henry Excel Worksheet Functions 1 February 25th 06 12:07 AM
How do I combine the contents of multiple cells in one cell? Debbie Excel Worksheet Functions 3 December 16th 05 10:57 PM
Combine "Total" and cell contents cottage6 Excel Programming 2 April 5th 05 05:57 PM


All times are GMT +1. The time now is 09:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"