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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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

Forum statistics

Threads
1,223,888
Messages
6,175,203
Members
452,617
Latest member
Narendra Babu D

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