I'm working in Excel on a VBA project, and want part of my macro to prompt the user to select a range of cells*, which the macro can later do stuff with.
*The type of prompt you get when creating a chart, or using a GUI to insert a function
e.g. here:
and here:
I'm therefor looking for something along the lines of
Sub MyMacro()
MsgBox "Please select data range"
' allow user to select range (as images above)
CreateFunctionArgumentsPrompt()
'do stuff with user selected range of cells
...
End Sub
Is it possible to access built-in Excel functionality to perform what I refer to as: CreateFunctionArgumentsPrompt()
Note: this is similar to SO question excel vba get range of user selected range by mouse but differs in that
To copy a cell or a range of cells to another worksheet you need to use the VBA's “Copy” method. In this method, you need to define the range or the cell using the range object that you wish to copy and then define another worksheet along with the range where you want to paste it.
Find and Highlight Duplicates in a Column Using Excel VBA ❶ First of all, press ALT + F11 to open the VBA editor. ❷ Then go to Insert >> Module. ❸ Copy the following VBA code. ❹ Paste and Save the code in the VBA editor.
Notes. This macro allows you to get data from another workbook, or put data into it, or do anything with that workbook. The code is a template that allows you to simply access another Excel file.
This isn't using the built in that you showed above, but does allow you to select a range of cells following an income prompt:
Sub RangeSelectionPrompt()
Dim rng As Range
Set rng = Application.InputBox("Select a range", "Obtain Range Object", Type:=8)
MsgBox "The cells selected were " & rng.Address
End Sub
This is based on the answer given in this MrExcel answer.
Here is how it looks in use:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With