View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
AJL AJL is offline
external usenet poster
 
Posts: 18
Default Copy from a Cell to a text box.

I put the message boxes in, and the macro does run to completion. The text
however, still does not appear in the text box, and it is indeed a shape. I
noticed in the message boxes, some of the text returned in the cells is being
truncated when selected. Is it possible that I have exceded some sort of
character limit that is preventing my text from pasting into the text box?
if so, is it possible to overcome that limit? There is definately more text
retuning from the vlookup and it is present in the cell. When I print my
strTextBox buffer however, only a portion appears.

"John Michl" wrote:

Add the message boxes below and it should help you find where the
problem is. If Box 3 shows nothing after the = sign the problem then
is with your code between the For and Next statements. If Box 3 does
have a result, then the problem is with the with Shapes statement which
may indicate that you are using a control rather than a shape.

- John

Sub AddTextToBox()
Dim strTextBox As String
MsgBox "Box 1. Starting macro."

For Each cell In Range("A1:A5")
MsgBox "Box 2. " & cell.Address & " - contents = " & cell.value
strTextBox = strTextBox & cell.Value & Chr(10)
Next cell

MsgBox "Box 3. Contents of strTextBox = " & strTextBox

ActiveSheet.Shapes("Text Box 1").TextFrame.Characters.Text =
strTextBox

MsgBox "Box 4. Done."

End Sub



AJL wrote:
I entered the macro script you gave me, changing the range to the appropriate
range that contains my vlookups returning text, and the name of the text box
to the correct box. I then assigned the macro to a button. Running the
macro however doesn't put the text in the box, it gives no errors either, it
seems like nothing is happening.

"John Michl" wrote:

Alan -
This simple code will get you started. Range A1:A5 is where the data
is stored. Modify this to suit your needs. You may also need to
change the text box name if you have multiple text boxes on the sheet.

Sub AddTextToBox()

Dim strTextBox As String

For Each cell In Range("A1:A5")
strTextBox = strTextBox & cell.Value & Chr(10)
Next cell

ActiveSheet.Shapes("Text Box 1").TextFrame.Characters.Text =
strTextBox

End Sub

- John
www.johnmichl.com/exceltips.htm

AJL wrote:
Hello,
I am trying to copy and paste the text returned by several vlookup formulas
to a text box. The amount of text returned to the cells is quite large.
When I set the text box equal to one of the cells, only a portion of the text
appears in the text box. When I set it equal to a range of cells I get
nothing. Is it possible to generate a macro that will copy and paste large
amounts of text that result from numerous equations into a text box?
Thanks.

-Alan Lueke