Excel VB Textobxes Characters

Jerome_RA

Board Regular
Joined
Dec 26, 2016
Messages
53
Office Version
  1. 2013
Platform
  1. Windows
Hi Excel Gurus,

I nee a help on a cod to separate Texts at Textboxes.

So I have here TextBoxComments, TextBoxA, TextBoxB, and TextBoxC.

So the TextBoxComments is where the user would place the comments on the file.

What I want to do is whenever the TexBoxComments reaches its first 255 characters, it will go to TextBoxA, the next succeeding 255 characters will go to TextBoxB and the last succeeding 255 characters will go to TextBoxC.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Enter all text in TextBoxComments and then run the code

Code below written for active-x textboxes embedded in a worksheet
Code simplified to make it easy to follow
Place code in SHEET module (not Module1, Module2 etc)

Code:
Sub Trans()
    Dim c As String
    c = TextBoxComments.Text
    
    TextBoxComments = Left(c, 255)
    TextBoxA = Mid(c, 255 + 1, 255)
    TextBoxB = Mid(c, 255 + 255 + 1, 255)
    TextBoxC = Mid(c, 255 + 255 + 255 + 1, 255)
End Sub


EDIT
Did I misread your request? Is it this you want?

Code:
Sub Trans()
    Dim c As String
    c = TextBoxComments.Text
    
    TextBoxComments = ""
    TextBoxA = Left(c, 255)
    TextBoxB = Mid(c, 255 + 1, 255)
    TextBoxC = Mid(c, 255 + 255 + 1, 255)
End Sub
 
Last edited:
Upvote 0
What do you want to happen if the delete key is pressed (in TextBoxComments), do you want the characters to come back from TextBoxA to Comments?
 
Upvote 0
Works like a charm. Thank you so much!!!!!



Enter all text in TextBoxComments and then run the code

Code below written for active-x textboxes embedded in a worksheet
Code simplified to make it easy to follow
Place code in SHEET module (not Module1, Module2 etc)

Code:
Sub Trans()
    Dim c As String
    c = TextBoxComments.Text
    
    TextBoxComments = Left(c, 255)
    TextBoxA = Mid(c, 255 + 1, 255)
    TextBoxB = Mid(c, 255 + 255 + 1, 255)
    TextBoxC = Mid(c, 255 + 255 + 255 + 1, 255)
End Sub


EDIT
Did I misread your request? Is it this you want?

Code:
Sub Trans()
    Dim c As String
    c = TextBoxComments.Text
    
    TextBoxComments = ""
    TextBoxA = Left(c, 255)
    TextBoxB = Mid(c, 255 + 1, 255)
    TextBoxC = Mid(c, 255 + 255 + 1, 255)
End Sub
 
Upvote 0
glad it helped
thanks for the feedback
(y)
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,179
Members
448,871
Latest member
hengshankouniuniu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top