2013-05-01 36 views
1
Dim FromRang As Range, ToRang As Range 
Dim UserCell As Range 
'Ask the user to input the cell Range in which to search for the sub strings 
    Set FromRang = Application.InputBox(Prompt:="Enter Search Range From:", Type:=8) 
    Set ToRang = Application.InputBox(Prompt:="Enter Search Range To:", Type:=8) 

For each UserCell in ("FromRang:ToRang") 

for循环提供可变的循环给类型不匹配错误如何通过一系列

请帮助..

回答

3

说完看着你前面的问题,你不需要两个独立变量来捕捉范围。

Set fullRange = Application.InputBox(Prompt:="Enter Search Range:", Type:=8)
即您可以在输入框处于活动状态时选择范围。此外,您还可以在A1:A10

类型,然后,你可以做

For each UserCell in fullRange 
    ... 
Next 
+0

很好的改善+1。 – 2013-05-01 15:54:25

+0

@shahkalpesh如果For语句不是“对于fullRange.Cells中的每个UserCell”? – Marshall 2013-05-01 17:20:18

+0

这工作..谢谢@shahkalpesh – 2013-05-01 17:33:18