|
本帖最后由 iilearning 于 2012-3-18 17:09 编辑
Sub test()
Dim rg As Range, i As Integer
' If Application.section = Null Then '在没有选择范围时如何强迫用户选择?
' MsgBox "请选择范围"
' End If
Set rg = Selection
For i = 1 To rg.Count
If IsNumeric(rg(i)) And rg(i) <> "" Then
If rg(i) > 0 Then
rg(i) = "正数"
ElseIf rg(i) = 0 Then
rg(i) = "零"
ElseIf rg(i) < 0 Then
rg(i) = "负数"
End If
End If
Next
End Sub
'选择正数
Sub 选择正数()
Dim rg As Range
Dim xz As Range
Dim i, x As Integer
Set rg = Application.InputBox("选择范围", "正数筛选", , , , , , 8)
' If rg = "" Then
' MsgBox "你没有选定范围"
' ElseIf rg = "False" Then
' End If
'Set rg = Selection
For i = 1 To rg.Count
If IsNumeric(rg(i)) And rg(i).Value > 0 Then
Set xz = rg(i)
GoTo 100
End If
Next
MsgBox "选择范围内没有正数"
Exit Sub
100:
For x = i + 1 To rg.Count
If IsNumeric(rg(x)) And rg(x).Value > 0 Then
Set xz = Union(xz, rg(x))
End If
Next
xz.Select
End Sub
'选择零所在的行
Sub 选择零所在的行()
Dim rg As Range
Dim xz As Range
Dim i, x As Integer
Set rg = Selection
For i = 1 To rg.Count
If IsNumeric(rg(i)) And rg(i).Value = 0 And rg(i).Value <> "" Then
Set xz = rg(i)
GoTo 100
End If
Next
MsgBox "选择范围内没有零"
Exit Sub
100:
For x = i + 1 To rg.Count
If IsNumeric(rg(x)) And rg(x).Value = 0 And rg(x).Value <> "" Then
Set xz = Union(xz, rg(x))
End If
Next
xz.EntireRow.Select
End Sub
'选择负数所在的列
Sub 选择负数所在的列()
Dim rg As Range
Dim xz As Range
Dim i, x As Integer
Set rg = Selection
For i = 1 To rg.Count
If IsNumeric(rg(i)) And rg(i).Value < 0 Then
Set xz = rg(i)
GoTo 100
End If
Next
MsgBox "选择范围内没有负数"
Exit Sub
100:
For x = i + 1 To rg.Count
If IsNumeric(rg(x)) And rg(x).Value < 0 Then
Set xz = Union(xz, rg(x))
End If
Next
xz.EntireColumn.Select
End Sub
|
|