通过vba excel将包含字符串的升序数字排序范围 [英] Sorting range in ascending numerical order containing strings by vba excel

查看:178
本文介绍了通过vba excel将包含字符串的升序数字排序范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下字符串的范围:

i have a range containing the following strings:

step_1,step_10,step_3,step_2

step_1, step_10, step_3, step_2

以下代码

input_sh.Activate
With ActiveSheet
    .Range("H2:H20").Select
    .Sort.SortFields.Clear
    .Sort.SortFields.Add Key:=Range("H2"), _
       SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortTextAsNumbers 'xlSortNormal
With .Sort
        .SetRange Range("H2:H20")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
End With

step_10,step_1, step_2,step_3

step_10, step_1, step_2, step_3

但我想获得

step_1,step_2,step_3,step_10

step_1, step_2,step_3,step_10

推荐答案

我会将数字分隔成另一列,最后一个+1,使用中间函数并排序。

I would separate the number into another column, your last + 1, using mid function and sort on that.

编辑:我不在我的电脑,但我认为你唯一的办法是设置一个宏:

I'm not at my pc but I think your only way to do this is to setup a macro that:


  1. 过滤你的

  2. 在第2行之前剪切并插入。

  3. 自行排序。


  1. Filter your sheet by the first 9.
  2. Cut and insert them before row 2.
  3. Sort these on their own.
  4. Then remove the filter and sort the rest as you have above.

这篇关于通过vba excel将包含字符串的升序数字排序范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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