alphabetize cells containing extra characters

ThomasOES

Board Regular
Joined
Aug 29, 2017
Messages
174
Hello
I would like to alphabetize a row of chemical elements. Some of the elements have extra characters. What code to alphabetize based on chemical symbol? Below is a sample of the data.

AlCrCu X99%MoSiVCNi X95%

Thanks for any help

Tom
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
If all you want to do is sort alphabetically but across one row instead of in a column, I think this code should work for you. I just pasted your data into a worksheet for testing, so you'll probably need to revise the actual sort range. Hope that helps!

VBA Code:
Sub SortaRow()
'Crafted 28 Jul 2020 by Wookiee at Mr Excel

With ActiveSheet.Sort

   .SortFields.Clear
   .SortFields.Add Key:=Range("A1:H1"), _
      SortOn:=xlSortOnValues, _
      Order:=xlAscending, _
      DataOption:=xlSortNormal
   .SetRange Range("A1:H1")
   .Orientation = xlLeftToRight
   .Apply
   
End With

End Sub
 
Upvote 0
I was trying
VBA Code:
Range("B34:I34").Sort Range("B34:I34"), , , , , , , , , , 1
Seems like it should work, but doesnt
 
Upvote 0
Just fixed it
Code:
Range("B34:I34").Sort Range("B34"), , , , , , , , , , 2
was sorting by rows instead of columns
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,286
Members
449,076
Latest member
kenyanscott

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