我想在excel中按字母顺序对每个单元格进行排序 [英] i want to sort each cell alphabetically in excel

查看:98
本文介绍了我想在excel中按字母顺序对每个单元格进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张包含'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

推荐答案

您必须使用VBA宏执行此操作。



每个单元格在工作表中,将内容作为单个项目拆分为数组,对数组进行排序,然后使用新数据更新单元格。



此功能有效

You will have to do this using a VBA macro.

For each cell in your worksheet, split the contents as individual items into an array, sort the array, then update the cell with the new data.

This function works
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


(10)
sorted = Left
(10) sorted = Left


(已排序,Len(已排序) - 1

' 更新具有已排序字符串的单元格
aCell.Value2 =已排序
结束 Sub
(sorted, Len(sorted) - 1) 'Update the cell with the sorted string aCell.Value2 = sorted End Sub

我没有在这里复制排序功能 - 你可以在 http找到一个很好的例子://www.cpearson.com/excel/SortingArrays.aspx [ ^ ]

要调用代码,请执行以下操作:

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中按字母顺序对每个单元格进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆