select多个单元格时,VBA中的Exceltypes不匹配错误13

我是一个新的VBA,我遇到了一个小问题。 当我只select一个单元格时,代码工作正常。 但是,当我尝试select多个单元格时,表示types不匹配。 我感谢任何帮助:)这里是代码:

Sub Asterisk() Dim Cell As Range If Selection.Value = "<.0001" Then Selection.Value = 0.0001 Else Selection.Value = Selection.Value If (Selection.Value < 0.001) Then Selection.Value = "***" ElseIf (Selection.Value >= 0.001) And (Selection.Value < 0.01) Then Selection.Value = "**" ElseIf (Selection.Value >= 0.01) And (Selection.Value < 0.05) Then Selection.Value = "*" Else Selection.Value = "Not significant" End If End If End Sub 

按照tigeravatar的build议,这里是你将如何使用a来循环select单元格

 Sub Asterisk() Dim Cell As Range For Each Cell In Selection If Cell.Value = "<.0001" Then Cell.Value = 0.0001 Else Cell.Value = Cell.Value If (Cell.Value < 0.001) Then Cell.Value = "***" ElseIf (Cell.Value >= 0.001) And (Cell.Value < 0.01) Then Cell.Value = "**" ElseIf (Cell.Value >= 0.01) And (Cell.Value < 0.05) Then Cell.Value = "*" Else Cell.Value = "Not significant" End If End If Next Cell End Sub