checking if a cell contains text and deleting it

jaycee

Active Member
Joined
Jul 22, 2009
Messages
323
I have a column (D) that contains letters and numbers ie e6788764, But if this row contains the letters "D", "F", "K" or "S" then I need to delete those letters but keep the numbers.
The length of the numbers also differ.

Any ideas how this can be done?
:confused:
 

Some videos you may like

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,920
This will do the job

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(D1, "D", ""),"F", ""),"K", ""),"S", "")
 

Steeviee

Active Member
Joined
Sep 9, 2009
Messages
380
Not sure if there is loads of data, if so you might want to replace the offending cells?

Anyway, example of simplified bit of code:
Code:
Sub try()
x = 2
Do Until x = 10
If Left(Cells(x, 4), 1) = "d" Then
Cells(x, 4) = Right(Cells(x, 4), Len(Cells(x, 4)) - 1)
End If
x = x + 1
Loop
End Sub
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,920

ADVERTISEMENT

That fromula goes in row 1 of a helper column,
is dragged down to the end of the data,
and (perhaps) copy/Paste Special Values the result into Column D.
 

jaycee

Active Member
Joined
Jul 22, 2009
Messages
323
I tried to put it in row "D" but this then deletes when I put the data in.

I have also tried in a seperate column, but this only copies what was in the original row "D" admittedly with those letters deleted, but now in the wrong column?
 

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,808
Office Version
  1. 365
Platform
  1. Windows
Highlight the range with the values in column D.

Hit CONTROL+H (Find & Replace)
Find: E
Replace: <leave this blank>

Hit Replace All.

Repeat for other letters in the column that you wish to remove.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,482
Messages
5,601,920
Members
414,482
Latest member
morkar

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
Top