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
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Can you be more specific about the algorithm to extract words from the sentence? How do we know that "Blue, Silver" goes into one textbox and "Red, Gold 258" into the second?
 
Upvote 0
I have over 6000 sentences of a similar type and on each sentence I need to separate the first two words which are separated by a comma in a separate Textbox for further manipulation and copying. The first two words in this example are Blue, Silver and they should be transferred to textbox1 and the last two words Red, Gold 258 goes to TextBox2. So formula should always copy the first two words and the last two words in a sentence, and there are about 6,000 of them. I only managed to copy the first word with this formula. I hope I was clear this time. :)
 
Upvote 0
Can you be more specific about the algorithm to extract words from the sentence? How do we know that "Blue, Silver" goes into one textbox and "Red, Gold 258" into the second?
I have over 6000 sentences of a similar type and on each sentence I need to separate the first two words which are separated by a comma in a separate Textbox for further manipulation and copying. The first two words in this example are Blue, Silver and they should be transferred to textbox1 and the last two words Red, Gold 258 goes to TextBox2. So formula should always copy the first two words and the last two words in a sentence, and there are about 6,000 of them. I only managed to copy the first word with this formula. I hope I was clear this time. :)
 
Upvote 0
"Red, Gold 258" looks like two words and a number to me.

Do you have additional examples?
 
Upvote 0
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))
 
Upvote 0
"Red, Gold 258" looks like two words and a number to me.

Do you have additional examples?
Modell fail.jpg
Modell.jpg
I fail with the first form, I managed to do only one sentence.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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