ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA Userform Textbox help (https://www.excelbanter.com/excel-programming/397232-vba-userform-textbox-help.html)

Joey_83

VBA Userform Textbox help
 
Hi All,
This might sound like a dumb question (which it probably is) but can
someone help me with the below code?

I have a userform called NCCC1 and I want to copy the text (which is
over 255 characters) from the textbox to a cell. I am getting an
object required error message and I can only seem to find help for
copying from drawing textboxes not userform textboxes.
Is there a difference?

Private Sub btnSave_Click()

Application.ScreenUpdating = False
Dim r As Range
Dim b As Variant
Dim i As Integer

Set r = ActiveWorkbook.Worksheets("Comments1").Range("A1")
b = Me.txtbox1.Text
'--codes breaks here--
r.Value = b.Characters(1, 255).Text
For i = 256 To b.Characters.Count Step 255
r.Value = r.Value & b.Characters(i, 255).Text
Next i
r.WrapText = False

End Sub


Mike H

VBA Userform Textbox help
 
Hi,

I may have misunderstood but if all you want to do is copy the contents of
the texbox tp A1 then this will do it:-

Private Sub CommandButton1_Click()
Dim r As Range
Set r = ActiveWorkbook.Worksheets("Comments1").Range("A1")
b = Me.TxtBox1.Text
r.Value = b
End Sub


Mike

"Joey_83" wrote:

Hi All,
This might sound like a dumb question (which it probably is) but can
someone help me with the below code?

I have a userform called NCCC1 and I want to copy the text (which is
over 255 characters) from the textbox to a cell. I am getting an
object required error message and I can only seem to find help for
copying from drawing textboxes not userform textboxes.
Is there a difference?

Private Sub btnSave_Click()

Application.ScreenUpdating = False
Dim r As Range
Dim b As Variant
Dim i As Integer

Set r = ActiveWorkbook.Worksheets("Comments1").Range("A1")
b = Me.txtbox1.Text
'--codes breaks here--
r.Value = b.Characters(1, 255).Text
For i = 256 To b.Characters.Count Step 255
r.Value = r.Value & b.Characters(i, 255).Text
Next i
r.WrapText = False

End Sub




All times are GMT +1. The time now is 01:52 PM.

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