在Excel VBA中validationvariables是否包含有效范围地址

我试图得到一个值的范围地址值到一个variables。

searchWrd = InputBox("Please enter the column name of first word/token's", "Search String", "J1") 

我需要validationvariablessearchWrd是否包含有效地址。 另外什么应该是variablessearchWrd的数据types

我会一起去的

 searchWrd = Application.InputBox("lease enter the column name of first word/token's", "Search String", ,,,,,8) 

有关更多信息,请阅读此: https : //msdn.microsoft.com/en-us/library/office/ff839468.aspx

基本上,最后的8设置inputtypes是一个范围。 请注意,这也会让你马上Dim searchWrd as Range

您可以尝试使用正常的If-Then-construct来validation从Inputbox中获得的文本。 为了获得正确的数据types,我们需要知道什么应该是可能的input到input框。 通常我会尝试获取searchstring所在的行/列的行号/列号。 或者,更好的办法是自己问一下string,然后编写代码来查找它所在的位置。 所以我只需要检查拼写错误,并给出一个消息,该string未find。 最好是问我想想的范围。