alphabetize cells containing extra characters

ThomasOES

Board Regular
Joined
Aug 29, 2017
Messages
129
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
 

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Wookiee

Active Member
Joined
Nov 27, 2012
Messages
330
Office Version
  1. 2016
Platform
  1. Windows
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
 

ThomasOES

Board Regular
Joined
Aug 29, 2017
Messages
129
I was trying
VBA Code:
Range("B34:I34").Sort Range("B34:I34"), , , , , , , , , , 1
Seems like it should work, but doesnt
 

ThomasOES

Board Regular
Joined
Aug 29, 2017
Messages
129
Just fixed it
Code:
Range("B34:I34").Sort Range("B34"), , , , , , , , , , 2
was sorting by rows instead of columns
 

Watch MrExcel Video

Forum statistics

Threads
1,123,488
Messages
5,601,976
Members
414,488
Latest member
rjp847

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