如何在for循环中提供一个variables来遍历一个范围

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") 

给出types不匹配错误

请帮忙..

看了你以前的问题,你不需要两个单独的variables来捕捉范围。

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

然后,你可以做

 For each UserCell in fullRange ... Next