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

查看:52
本文介绍了通过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

推荐答案

我会使用 mid 函数将数字分成另一列,即你的最后一个 + 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. 按前 9 个过滤您的工作表.
  2. 在第 2 行之前剪切并插入它们.
  3. 自行排序.
  4. 然后删除过滤器并按照上面的方式对其余部分进行排序.

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

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