通过查看前几个字符,数字化excel vba排序表 [英] excel vba sort sheet numerically by looking at first few characters

查看:193
本文介绍了通过查看前几个字符,数字化excel vba排序表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的excel文件中排序表格。我的工作表名称是12_abc,122_adf,3_dasf,11_ad等。我想根据我的工作表名称中的(第一个下划线)之前的数字排序工作表。在进行排序时,代码应该明白3应该出现在134之前。代码需要在之前取文本并将其转换为数字。



我可以做同样的事吗?这个问题与此问题非常相似。我根据我收到的意见发布了一个新问题。

解决方案

尝试...

  Sub SortSheetTabsAscending()
Dim ws As Worksheet
Dim i As Integer,j As Integer

Application.ScreenUpdating = False
设置ws = ActiveSheet
对于i = 1 To Sheets.Count
对于j = 1 To Sheets.Count - 1
如果Split(Sheets(j) .Name,_)(0)+ 0>分割(表格(j + 1).Name,_)(0)+ 0然后
表格(j).Move之后:=表格(j + 1)
结束如果
下一步j
下一步i
ws.Activate
Application.ScreenUpdating = True
End Sub


I want to sort sheets in my excel file. My sheet names are 12_abc, 122_adf, 3_dasf, 11_ad etc. I would like to sort sheets based upon number before "" (first underscore) in my sheet name. While doing the sorting the code should understand that 3 should appear before 134. The code needs to take text before "" and convert it to number.

How could I do the same? This question is very similar to this question. I am posting a new question based upon comments that I received

解决方案

Give it a try...

Sub SortSheetTabsAscending()
Dim ws As Worksheet
Dim i As Integer, j As Integer

Application.ScreenUpdating = False
Set ws = ActiveSheet
For i = 1 To Sheets.Count
    For j = 1 To Sheets.Count - 1
        If Split(Sheets(j).Name, "_")(0) + 0 > Split(Sheets(j + 1).Name, "_")(0) + 0 Then
            Sheets(j).Move After:=Sheets(j + 1)
        End If
    Next j
Next i
ws.Activate
Application.ScreenUpdating = True
End Sub

这篇关于通过查看前几个字符,数字化excel vba排序表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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