How to delete string from cells if it contains the letter x ?

Tardisgx

Board Regular
Joined
May 10, 2018
Messages
81
9X60X11

I have variations of dimensions such as the string above in my cells. Their position is not consistent. The only consistent rule is that the word I want to be rid off in all my cells contains the letter x, but how?
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hopefully, this formula will return only those values that you want

=IF(ISBLANK(A1),"",IFERROR(IF(SEARCH("x",A1)>0,""),A1))
 
Upvote 0
or to return the values containing X

=IF(ISBLANK(A1),"",IFERROR(IF(SEARCH("x",A1)>0,A1),""))
 
Upvote 0
Hi the formula does not operate as needed. At the moment the entire cell is cleared; I want to delete any word containing the letter x

A1 Red Bear Table 60x31x40

A1 Red Bear Table
 
Upvote 0
You forgot to say that the other text in the cell could also contain "X" - a different approach is needed
Please provide 20 typical but varied examples so that anyone looking at this understands the variety of strings to remove (and position within cell text), so that a proposed solution can be adequately tested
thank you
 
Upvote 0
You forgot to say that the other text in the cell could also contain "X"

https://imgur.com/a/GKOzbTl

As I said
"At the moment the entire cell is cleared"
&
"The only consistent rule is that the word I want to be rid off in all my cells contains the letter x"

I do not know why you believe in the formula over my feedback; so I've screenshotted proof; the formula is also active in B25. I do appreciate your input.
 
Upvote 0
I do not know why you believe in the formula over my feedback
I did not say that - please read my reply again :)

"The only consistent rule is that the word I want to be rid off in all my cells contains the letter x"
Please reconsider your rule
Is it impossible for the other text in your cell to contain "X"? (Faux Leather Chair 20X20X20, Luxury Table 30X30X30 etc)

If you paste the sample data requested in post#5 into your reply, I will look at it later
(not a screenshot - I want to paste it into a test workbook)

thank you
 
Last edited:
Upvote 0
"The only consistent rule is that the word I want to be rid off in all my cells contains the letter x"

I do not know why you believe in the formula over my feedback; so I've screenshotted proof; the formula is also active in B25. I do appreciate your input.

Hi,

Yongle is just trying to Clarify the different types/formats of strings you have.
And as pointed out, I also don't believe we can use the letter X as a rule, I'm fairly certain some of your Text strings will contain 1 or more X other than the Part you want removed.

You said they are dimensions, so I'm assuming the X is Always surrounded by numbers.
This formula will work if there's only One set of dimensions within the Text string:


Book1
BCD
1Fork Oil Seal Kit &DustCapFork Oil Seal Kit 41X54X11 &DustCap
2Red Bear TableRed Bear Table 60x31x40
3Red Bear Table no sizeRed Bear Table no size
4Extra Large exampleExtra Large 100x200X300 example
Sheet217
Cell Formulas
RangeFormula
B1=TRIM(SUBSTITUTE(D1,TRIM(LEFT(SUBSTITUTE(MID(D1,MIN(FIND({0,1,2,3,4}+{0;5},D1&1/17)),255)," ",REPT(" ",99)),99)),""))


Formula copied down.
 
Upvote 0
Just for the heck of it, until something normal comes around.
All data in Column A, starting at A2.
Code:
Sub AAAAC()
Dim c As Range
    For Each c In Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)
        If InStr(InStrRev(c.Value, " ", InStr(1, c.Value, "x")) + 1, c.Value, " ") = 0 Then
            c.Offset(, 1).Value = Left(c.Value, InStrRev(c.Value, " ", InStr(1, c.Value, "x")) - 1)
                Else
            c.Offset(, 1).Value = Left(c.Value, InStrRev(c.Value, " ", InStr(1, c.Value, "x")) - 1) & Mid(c.Value, _
            InStr(InStrRev(c.Value, " ", InStr(1, c.Value, "x")) + 1, c.Value, " "), 99)
        End If
    Next c
End Sub

Non of the data, outside of the measurements, should have an "x" in it!
 
Last edited:
Upvote 0
Hi,

Worksheet Formulas
CellFormula
B1=TRIM(SUBSTITUTE(D1,TRIM(LEFT(SUBSTITUTE(MID(D1,MIN(FIND({0,1,2,3,4}+{0;5},D1&1/17)),255)," ",REPT(" ",99)),99)),""))

<tbody>
</tbody>

<tbody>
</tbody>

Hi jtakw,

Nice one........Can you please explain how this term works?

'MIN(FIND({0,1,2,3,4}+{0;5},D1&1/17))'
 
Upvote 0

Forum statistics

Threads
1,215,093
Messages
6,123,068
Members
449,091
Latest member
remmuS24

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