VBA用户表单范围到variables语法问题

我已经在Excel中创build了一个VBA Userform,用户可以在其中select几个范围。 在用户表单中,我通过一系列If和MsgBox语句inputvalidation。

作为其中的一部分,我需要把input的范围作为一个variables。

假设范围是Me.ActDurations,我试图用这个:

dim ActDur as range set ActDur = Me.ActDurations 

我也试过:

 set ActDur = Me.ActDurations.Value 

而这也是行不通的。 什么是适当的语法呢? 使用第一种types给我一个types不匹配的错误。

RefEdit.Value属性返回一个string。 要将它用作范围,您应该使用该string作为范围名称。 下面的示例代码。

 Dim address as String Dim targetRange As Range address = RefEdit1.Value 'String returned by the selected range using RefEdit. Set targetRange = Range(address) 'Do some code here. 

根据需要修改您的代码。 ;)