Leave only letters in range of cells vba

ThomasOES

Board Regular
Joined
Aug 29, 2017
Messages
174
Hello

How to leave only letters (element symbols) in a range of cells. The range begins at E1. Each element (Ex. Al240 %) is one cell.

Make this:

Al240%As189%B208%C165%Ca393%Co340%Cr267%Cu327%Fe249%Mn_Calc.Mo386%Nb400%Ni341%P177%Pb220%S180%Sb206%Si_Calc.Sn326%Ta362%Ti337%V411%W400%Zr360%

<tbody>
</tbody>


Look like this:

AlAsBBeCCaCoCrCuFeLaMgMnMoN!NbNiPPbSSbSiSnTaTiVWZnZr

<tbody>
</tbody>

Also remove any spaces and the phrase "Calc".

Thanks for any help

Tom
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Prob a better way but this seems to work

Code:
Sub k1()
lastcol = Worksheets("Sheet1").Cells(1, Columns.Count).End(xlToLeft).Column
For i = 5 To lastcol
Cells(2, i) = Left(Cells(1, i), 2)
Next
End Sub
 
Last edited:
Upvote 0
Another option
Code:
Sub GetElements()
   With Range("E1", Cells(1, Columns.Count).End(xlToLeft))
      .Value = Evaluate(Replace("if(isnumber(mid(@,2,1)*1),left(@,1),left(@,2))", "@", .Address))
   End With
End Sub
 
Upvote 0
I tried this and it works great to remove the phrase and %. How to .Replace What:=numbers, Replacement:=""


Code:
Range("E1", Selection.End(xlToRight)).Select
For Each cell In Selection
With cell
    .Replace What:="_Calc.", Replacement:=""
    .Replace What:=" %", Replacement:=""
End With
Next

Tom
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,941
Members
449,094
Latest member
teemeren

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