Reputation: 546
I've created a VBA Userform in Excel, where the user selects several ranges. Within the user form, I have input validation through a series of If then MsgBox statements.
As part of this, I need to take the inputted range and use it as a variable.
Assuming that the range is Me.ActDurations, I tried to use this:
dim ActDur as range
set ActDur = Me.ActDurations
I've also tried:
set ActDur = Me.ActDurations.Value
And that doesn't work either. What is the proper syntax for this? Using the first type gives me a type mismatch error.
Upvotes: 0
Views: 810
Reputation: 14169
The .Value
property of RefEdit
returns a string. To use it as a range, you should use the string as a range name. Sample code below.
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.
Modify as necessary for your code. ;)
Upvotes: 3