2
我在Excel中排序了一个非常大的范围,它由多个列组成,而不是所有列都被填充。在某些列中,有时会输入空格,并且单元格的时间为Empty
。我想要做的是将空白区域和空单元格移动到范围的底部。目前,excel将顶部的空白值和底部的空白单元格放在一起。或者,我不介意可以通过范围并用Empty
替代空白值的消毒功能。我写了一篇,但是我给出的范围非常慢(接近4000行,需要2分钟才能完成)。以及我发布的排序sub
我正在使用。Excel VBA排序范围,空白和空值在范围底部
我查看了自定义订单,但它看起来像需要您指定您计划使用的所有值。是否可以使用自定义比较功能,而无需编写全新排序sub
?
Sub SortCallLog()
Application.ScreenUpdating = False
Dim longTime As Double
longTime = Millis
Dim lastRow As Long
Dim ws As Worksheet
Dim sortOrder As Variant
Set ws = Worksheets("CallLog")
Call addToIndexesHV(FirstCBSort, SecondCBSort, ThirdCBSort, FourthCBSort) ' These are global variables referring to the sort order
sortOrder = getSortOrder(False)
lastRow = GetLastRow(ws)
With ws.Sort
.SortFields.Clear
For sortIndex = 0 To getVariantLength(sortOrder) - 1
.SortFields.Add Key:=Range(ConvertCBSortToColRow(CStr(sortOrder(sortIndex)))), Order:=xlAscending, SortOn:=xlSortOnValues, DataOption:=xlSortNormal
Next sortIndex
.Header = xlYes
.MatchCase = False
.SetRange ws.Range("B1:X" & (lastRow))
.Apply
End With
Debug.Print (Millis - longTime)
Application.ScreenUpdating = True
Exit Sub
消毒部
For Each cell In ws.Range("B2:L" & (lastRow)).Rows.Cells
cell.value = Trim(cell.value)
If "" = cell.value Then
cell.value = Empty
End If
Next cell
是的,那好多了,好多了。在我的机器上花了94毫秒。这应该使它更清晰,我认为这对我的应用程序来说已经足够了。谢谢。 – RWA4ARC