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:

[TABLE="width: 1536"]
<tbody>[TR]
[TD="width: 64, bgcolor: transparent"]Al240%[/TD]
[TD="width: 64, bgcolor: transparent"]As189%[/TD]
[TD="width: 64, bgcolor: transparent"]B208%[/TD]
[TD="width: 64, bgcolor: transparent"]C165%[/TD]
[TD="width: 64, bgcolor: transparent"]Ca393%[/TD]
[TD="width: 64, bgcolor: transparent"]Co340%[/TD]
[TD="width: 64, bgcolor: transparent"]Cr267%[/TD]
[TD="width: 64, bgcolor: transparent"]Cu327%[/TD]
[TD="width: 64, bgcolor: transparent"]Fe249%[/TD]
[TD="width: 64, bgcolor: transparent"]Mn_Calc.[/TD]
[TD="width: 64, bgcolor: transparent"]Mo386%[/TD]
[TD="width: 64, bgcolor: transparent"]Nb400%[/TD]
[TD="width: 64, bgcolor: transparent"]Ni341%[/TD]
[TD="width: 64, bgcolor: transparent"]P177%[/TD]
[TD="width: 64, bgcolor: transparent"]Pb220%[/TD]
[TD="width: 64, bgcolor: transparent"]S180%[/TD]
[TD="width: 64, bgcolor: transparent"]Sb206%[/TD]
[TD="width: 64, bgcolor: transparent"]Si_Calc.[/TD]
[TD="width: 64, bgcolor: transparent"]Sn326%[/TD]
[TD="width: 64, bgcolor: transparent"]Ta362%[/TD]
[TD="width: 64, bgcolor: transparent"]Ti337%[/TD]
[TD="width: 64, bgcolor: transparent"]V411%[/TD]
[TD="width: 64, bgcolor: transparent"]W400%[/TD]
[TD="width: 64, bgcolor: transparent"]Zr360%[/TD]
[/TR]
</tbody>[/TABLE]


Look like this:

[TABLE="width: 1920"]
<tbody>[TR]
[TD="width: 64, bgcolor: transparent"]Al[/TD]
[TD="width: 64, bgcolor: transparent"]As[/TD]
[TD="width: 64, bgcolor: transparent"]B[/TD]
[TD="width: 64, bgcolor: transparent"]Be[/TD]
[TD="width: 64, bgcolor: transparent"]C[/TD]
[TD="width: 64, bgcolor: transparent"]Ca[/TD]
[TD="width: 64, bgcolor: transparent"]Co[/TD]
[TD="width: 64, bgcolor: transparent"]Cr[/TD]
[TD="width: 64, bgcolor: transparent"]Cu[/TD]
[TD="width: 64, bgcolor: transparent"]Fe[/TD]
[TD="width: 64, bgcolor: transparent"]La[/TD]
[TD="width: 64, bgcolor: transparent"]Mg[/TD]
[TD="width: 64, bgcolor: transparent"]Mn[/TD]
[TD="width: 64, bgcolor: transparent"]Mo[/TD]
[TD="width: 64, bgcolor: transparent"]N![/TD]
[TD="width: 64, bgcolor: transparent"]Nb[/TD]
[TD="width: 64, bgcolor: transparent"]Ni[/TD]
[TD="width: 64, bgcolor: transparent"]P[/TD]
[TD="width: 64, bgcolor: transparent"]Pb[/TD]
[TD="width: 64, bgcolor: transparent"]S[/TD]
[TD="width: 64, bgcolor: transparent"]Sb[/TD]
[TD="width: 64, bgcolor: transparent"]Si[/TD]
[TD="width: 64, bgcolor: transparent"]Sn[/TD]
[TD="width: 64, bgcolor: transparent"]Ta[/TD]
[TD="width: 64, bgcolor: transparent"]Ti[/TD]
[TD="width: 64, bgcolor: transparent"]V[/TD]
[TD="width: 64, bgcolor: transparent"]W[/TD]
[TD="width: 64, bgcolor: transparent"]Zn[/TD]
[TD="width: 64, bgcolor: transparent"]Zr
[/TD]
[TD="width: 64, bgcolor: transparent"][/TD]
[/TR]
</tbody>[/TABLE]

Also remove any spaces and the phrase "Calc".

Thanks for any help

Tom
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,224,823
Messages
6,181,183
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