Home » excel » VBA How can I force the user to select a range using Excel's built in range selection?

VBA How can I force the user to select a range using Excel's built in range selection?

Posted by: admin May 14, 2020 Leave a comment

Questions:

What I would like to achieve is that as soon as the macro is run, the user has to select (by hand, from the Sheet and not by typing the range) a range that would then be set to a Range variable.

Excel does have such functionality in many areas, such as the Data selection settings for Charts but I don’t know how to access it. Any and all help is appreciated!

How to&Answers:

Below will force the user to select a Range:

On Error Resume Next

Dim rng As Range

Do
    Set rng = Application.InputBox(Prompt:="Select Range", Type:=8)
Loop While rng Is Nothing

If Not rng Is Nothing Then rng.Select

On Error GoTo 0