简体   繁体   中英

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

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM