问题描述
我有一张包含'n'列和'n'行的电子表格。在每个具有多个值的单元格中,我想按字母顺序对它们进行排序。
如果我试图对特定单元格进行排序意味着无法正常工作
然后,如果我选择单元格并且(它有多个项目)复制项目,
和然后粘贴到新的电子表格中意味着特定单元格的每个项目都已排序,但是将不同单元格中的每个项目放在单个单元格中。
在电子表格中,我想要排序每个单元格按字母顺序
I have a spread sheet that has 'n' columns and 'n' rows. In every cell having more than one values, i want to sort them in alphabetically.
If i tried to sort the particular cell means that will not work properly
And then if i select the cell and (it has more than one items) copy the items,
and then paste in new spreadsheet means every items of the particular cell sorted but put the every items in the different cells not in single cell.
in spreadsheet,i want to sort each cell alphabetically
推荐答案
Public Sub SortACell(aCell As Range, sep As String)
'Split the cell into its individual "values"
Dim S1() As String
S1 = Split(aCell.Value2, sep)
'Sort the array now containing the cell contents
'See http://www.cpearson.com/excel/SortingArrays.aspx
Dim b As Boolean
b = QSortInPlace(S1)
'Rebuild the cell contents
Dim sorted As String
Dim s2 As Variant
For Each s2 In S1
sorted = sorted & s2 & sep
Next
'Remove last chr
我没有在这里复制排序功能 - 你可以在 []
要调用代码,请执行以下操作:
I haven't reproduced the sorting functions here - you can find a good example at http://www.cpearson.com/excel/SortingArrays.aspx[^]
To call the code do something like this:
Range("A1").Select
Dim c As Range
For Each c In ActiveCell.CurrentRegion.Cells
If Trim(c.Value2) <> "" Then
SortACell c, Chr
这篇关于我想在excel中按字母顺序对每个单元格进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!