How to copy the first two words in the text line and two last or one word in line?

Masta

New Member
Joined
Feb 22, 2022
Messages
33
Office Version
  1. 2021
  2. 2019
  3. 2016
Platform
  1. Windows
This solution only works for one first word. Sample " Blue, Silver, line of production mixed with Red, Gold 258" ..... In this sentence, I need to single out the following words and numbers. In two different TextBoxes. I really need help with this program line. I don't have much experience with excel vba. "Blue, Silver and Red, Gold 258".

Private Sub CommandButton207_Click()
Dim ws As Worksheet
Set ws = Worksheets("Models")

ws.Range("K71") = Left(ws.Range("K70"), (Application.WorksheetFunction.Find((","), ws.Range("K70"), 1) - 1))

End Sub
 
You haven't given enough detail to write code specific for you. I don't know what your textboxes are called or where they are located. But this should give you the idea:

VBA Code:
   Dim A As Variant

   A = Split(ws.Range("K70"), " ")
   TextBox1 = A(0) & ", " & A(1)
   TextBox2 = A(UBound(A) - 1) & ", " & A(UBound(A))
i will try this i just send you couple of shoots how this look like in real.
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Looks like we posted at the same time. Please try my code. If it does not work, post all of your code here, and use code tags for readability.
 
Upvote 0
Looks like we posted at the same time. Please try my code. If it does not work, post all of your code here, and use code tags for readability.
Private Sub CommandButton207_Click()
TextBox57.Paste
Application.Wait (Now + TimeValue("0:00:01"))
Dim ws As Variant
Set ws = Worksheets("Models")
ws = Split(ws.Range("K70"), " ")
TextBox58 = ws(0) & ", " & ws(1)
TextBox59 = ws(UBound(ws) - 3) & " " & ws(UBound(ws) - 2) & " " & ws(UBound(ws) - 1)

Application.Wait (Now + TimeValue("0:00:01"))


TextBox58.SelStart = 0
TextBox58.SelLength = TextBox58.TextLength
TextBox58.Cut

TextBox2.SetFocus
TextBox2.SelStart = 0

TextBox2.Paste
TextBox58.SelStart = 0

TextBox59.SelStart = 0
TextBox59.SelLength = TextBox59.TextLength
TextBox59.Cut

TextBox3.SetFocus
TextBox3.SelStart = 0

TextBox3.Paste
TextBox59.SelStart = 0

End Sub

I paste copyed text directly with CommandButton207 into TextBox57 and i need to pause operation 1 sec to do this right if is no there pause data will not show correctly then after paste data goes to Worksheets("Models") to cell K70, then after that data is splited in to two parts.... first part goes to TextBox58 and second part goes to TextBox59, after that i have other part of program who dealing with splited data but that is no prob from that part everything goes smoooth.
I tweek little bit but i have other problems, when is no data in TextBox57 i got error >>"Run-time error '9' Subscript out of range"<< and i dont know how to fix this, and is there a way to sellect only text not number if i have some in line, numbers and slash shoving only on the end of sentence, in some situation i have like in this example i will demonstrate : Platinum_333 and without underscore Platinum 648/22 , i have prob when is the end with just numbers and slash . Tnx in advance :)
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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