Help with text box limit (1024)

I

irais

Hi

I need to store more than 1024 characters in a text box
(from a Form) and then save it into an excel cell.

If it is less than 1024 characters it works fine.

Any ideas?

All help is apreciated.

Irais.
 
D

Dan E

Irais,

The limit is of the cell, not the textbox. A cell can only store
1024 characters. So you need to break up the text before
putting it in the textboxes.

If Len(TextBox1.Value) > 1024 Then
Range("A1").Value = Left(TextBox1.Value, 1024)
Range("A2").Value = Mid(TextBox1.Value, 1025, Len(TextBox1.Value) - 1024)
Else
Range("A1").Value = TextBox1.Value
End If

That'll do it for a max of 2048 characters. If you need to go
beyond that, post back.

Dan E
 
I

Irais

It worked.
Thank you, Dan E!

Irais.
-----Original Message-----
Irais,

The limit is of the cell, not the textbox. A cell can only store
1024 characters. So you need to break up the text before
putting it in the textboxes.

If Len(TextBox1.Value) > 1024 Then
Range("A1").Value = Left(TextBox1.Value, 1024)
Range("A2").Value = Mid(TextBox1.Value, 1025, Len (TextBox1.Value) - 1024)
Else
Range("A1").Value = TextBox1.Value
End If

That'll do it for a max of 2048 characters. If you need to go
beyond that, post back.

Dan E




.
 
D

Dave Peterson

A cell in xl97 and up can contain up to 32767 characters. Excel's help says
that only 1024 are visible though. (you can get quite a few more if you add
some alt-enters in nice spots.)

I used xl2002 and made a small userform with a command button and a textbox and
I ran this code:

Option Explicit

Private Sub CommandButton1_Click()
Me.TextBox1.Value = Application.Rept("asdf ", 5000)
Range("a1").Value = Me.TextBox1.Text
MsgBox Len(Me.TextBox1.Value) & vbNewLine & Len(Range("a1").Value)
End Sub

The msgbox came back with 25000 for each.
 
D

Dan E

My mistake, you are correct. When checking I only scanned and now
see that I got 1024 from the "Length of formula contents" instead of the
"Length of cell contents (text)".

Regardless, I think it would be hard to use VBA to break up text (into
comprehensible chunks) using carefully positioned carriage returns.
Though their are probably better ways to break up the text than my
(cut it off at 1024) approach.

Thank you,

Dan E
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top