Deleting Particular Words based on Criteria

madhuchelliah

Board Regular
Joined
Nov 22, 2017
Messages
226
Office Version
  1. 2019
Platform
  1. Windows
Hello all, i have multiple words in cell C4. Words are combination of alpha, numeric and symbols. Among the multiple words, the code has to find the word "FOR" and delete it along with the word before to the FOR. Please go through the example for better clarity. Thank you.

Value in cell C4 = XXX$%, AD024 FOR fds^&bjb ZZZZ RRRR, SSS-SSS, 58-2457R1 FOR asdsd , asdd,dsda

Expected Result= XXX$%, fds^&bjb ZZZZ RRRR, SSS-SSS, asdsd , asdd,dsda
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
This seems to do it. HTH, Dave
Code:
Sub test()
Dim SplitIt As Variant, Cnt As Integer
Dim MyPos As Integer, Tstr As String, TempStr As String
SplitIt = Split(ActiveSheet.Range("C4"), ",")
For Cnt = LBound(SplitIt) To UBound(SplitIt)
If InStr(SplitIt(Cnt), "FOR") Then
MyPos = InStr(1, SplitIt(Cnt), "FOR", 1)
Tstr = Right(SplitIt(Cnt), Len(SplitIt(Cnt)) - (MyPos + 3))
TempStr = TempStr & Tstr & ","
Else
TempStr = TempStr & SplitIt(Cnt) & ","
End If
Next Cnt
MsgBox Left(TempStr, Len(TempStr) - 1)
End Sub
 
Upvote 0
Solution
This seems to do it. HTH, Dave
Code:
Sub test()
Dim SplitIt As Variant, Cnt As Integer
Dim MyPos As Integer, Tstr As String, TempStr As String
SplitIt = Split(ActiveSheet.Range("C4"), ",")
For Cnt = LBound(SplitIt) To UBound(SplitIt)
If InStr(SplitIt(Cnt), "FOR") Then
MyPos = InStr(1, SplitIt(Cnt), "FOR", 1)
Tstr = Right(SplitIt(Cnt), Len(SplitIt(Cnt)) - (MyPos + 3))
TempStr = TempStr & Tstr & ","
Else
TempStr = TempStr & SplitIt(Cnt) & ","
End If
Next Cnt
MsgBox Left(TempStr, Len(TempStr) - 1)
End Sub
Hello Dave, it is working as expected. Thanks for your time. Stay safe.
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

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