|
最开始编的第一个程序为
Sub 选取单元格区域内值为2的单元格()
Dim ran As Range
Dim ge As Range
For Each ge In Range("a1:e10")
If ge.value = 2 Then
Set ran = Union(ran, ge)
Exit For
End If
Next ge
ran.Select
End Sub
然后运行之后出现错误,于是查找发现是ran变量没有赋值
于是再写了一个程序
Sub 选取单元格区域内值为2的单元格()
Dim ran As Range
Dim ge As Range
For Each ge In Range("a1:e10")
If ge.value = 2 Then
Set ran = ge
Exit For
End If
Next ge
For Each ge In Range("a1:e10")
If ge.value = 2 Then
Set ran = Union(ran, ge)
End If
Next ge
ran.Select
End Sub
但我觉得第二个程序略显繁杂了,求高手指教,range变量有空值没有,或者说缺省值?另外我的第二个程序能否有简化?谢谢!
|
|