- 排序“B 列”<== 使用以下代码完成:
' sorts %change from cell B2 to the end of the line
Range("B2", Range("B2").End(xlDown)).Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlNo
数据:
输出:
- 仅选择负范围单元格
现在光标将位于值为 -33 的单元格(单元格 B2)中。 我需要选择值为 -33、-5 和 -2 的范围。有没有一种快速的方法(内置公式)可以在不评估每个单元格值的情况下识别这些范围?
注意:获取的数据是动态的,行数不固定。
最佳答案
在排序列中选择负值
Option Explicit
Sub Test()
With ActiveSheet.Range("A1").CurrentRegion
.Sort Key1:=.Columns(2), Order1:=xlAscending, Header:=xlYes
With .Columns(2).Resize(.Rows.Count - 1).Offset(1)
On Error Resume Next
.Resize(Application.CountIf(.Cells, "<0")).Select
On Error GoTo 0
End With
End With
End Sub
关于excel vba 选择负范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71747881/