Question

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.

Was it helpful?

Solution

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. ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top