在Vba EXCEL

时间:2016-06-06 16:42:13

标签: excel vba excel-vba

我在排序方面遇到问题 是不是正确排序,筛选只是第一个数字? 用于查找数字和插入数据的此解决方案或其他解决方案的任何解决方案?

锁定此图片  enter image description here

文件Excel:https://www.mediafire.com/?aoymmkqo1foaxqy

1 个答案:

答案 0 :(得分:0)

试试这个:

' Workbuuk
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets(1)

' Our used range
Dim rng As Range
Set rng = ws.UsedRange
Dim rngCell As Range ' cellie

' Mad Max
Dim lngMaxRow As Long
lngMaxRow = Range("B" & Rows.Count).End(xlUp).Row

' The heat is on
For Each rngCell In rng.Range("B1:B" & lngMaxRow)
    ' set a value to the left, to the left
    rngCell.Offset(0, -1).Value = Left(rngCell.Value, InStr(1, rngCell.Value, ".") - 1)
Next

' Sort on A, A, A . . .  .  under my umbrella, A, A, A, A-A
rng.Sort KeY1:=Range("A2"), Order1:=xlAscending

' The heat is off
For Each rngCell In rng.Range("B1:B" & lngMaxRow)
    ' Undo weah
    rngCell.Offset(0, -1).Value = ""
Next

假设:

  1. A栏是空的
  2. 您希望按数值排序,而不是整体字符串值
  3. 类别值格式以XX.YYYY开头,其中x是数字,y是字母