按字母顺序排列excel值

美好的一天! 我想问问是否有办法按字母顺序排列单元格的值?

示例列A

A,M A,Q Q,A M,A 

我想按字母顺序排列单个单元格的值。 没有对列进行sorting。

结果应该是这样的:

 A,M A,Q A,Q A,M 

你可以使用这个VBA代码,它使用这个答案进行sorting:

 Dim col As Variant Dim list As Variant Dim i As Long Dim part as Variant ' Create a list that can be used for sorting Set list = CreateObject("System.Collections.ArrayList") ' Get cell contents into an array and loop over each value col = ActiveSheet.UsedRange.Columns(1) For i = 1 To UBound(col) ' Extract the comma-separated values with Split and add them to the list list.Clear For Each part In Split(col(i, 1), ",") list.Add part Next ' Now use the handy Sort method on that list list.Sort ' Join the result back to the comma-separated format, and put it in the array col(i, 1) = Join(list.ToArray(), ",") Next ' Put the modified array contents back in the sheet where they came from ActiveSheet.UsedRange.Columns(1) = col