0

我希望用户输入单元格范围

Dim FromRang, ToRang As Range

'Ask the user to input the cell Range in which to search for the sub strings
FromRang = Application.InputBox(Prompt:="Enter Search Range From:", Type:=8)
ToRang = Application.InputBox(Prompt:="Enter Search Range To:", Type:=8)

但这给了我一个错误:“对象变量或块变量未在 excel vba 中设置”

4

1 回答 1

6

诸如 a 之类的对象Range只能在 VBA 中使用 Set 进行赋值。因此,正如我所说,您应该使用:

Set FromRang = Application.InputBox(Prompt:="Enter Search Range From:", Type:=8)

此外,为多个变量标注尺寸需要您分别声明每个变量的类型:

Dim FromRang As Range, ToRang As Range

否则第一个将是未指定的,默认情况下这会导致它成为Variant可能导致不良行为的类型。

于 2013-05-01T14:40:22.210 回答