PC Review


Reply
Thread Tools Rate Thread

Combine cell contents into a text box

 
 
hinick@gmail.com
Guest
Posts: n/a
 
      18th Jan 2007
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(msoTextOrientationHorizontal, 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 With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      19th Jan 2007

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



<(E-Mail Removed)>
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(msoTextOrientationHorizontal, 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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I combine cell contents? =?Utf-8?B?U3Rvcm0=?= Microsoft Excel Misc 1 13th Apr 2007 11:23 PM
Splitting text in one cell and combine in a new cell =?Utf-8?B?SmltUg==?= Microsoft Excel Worksheet Functions 1 21st Feb 2007 07:19 PM
Combining cell contents when there is content to combine =?Utf-8?B?UmljaGFyZA==?= Microsoft Excel Misc 2 21st Jun 2006 07:30 PM
How do I combine the contents of multiple cells in one cell? =?Utf-8?B?RGViYmll?= Microsoft Excel Worksheet Functions 3 16th Dec 2005 10:57 PM
How to combine contents of several cells into 1 cell (Not sum) SuperstarPunani Microsoft Excel Worksheet Functions 1 12th Dec 2003 04:14 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:24 PM.