Home » excel » Force VBA to display currently-selected cells when prompting user to select a range with Inputbox in Excel

Force VBA to display currently-selected cells when prompting user to select a range with Inputbox in Excel

Posted by: admin May 14, 2020 Leave a comment

Questions:

I know that I can use Inputbox to prompt the user to select a range

Set rng = Application.InputBox( _
  Title:="Number Format Rule From Cell", _
  Prompt:="Select a cell to pull in your number format rule", _
  Type:=8)

However when this code is executed, the inputbox will initially be empty

Empty Inputbox

How can I make it so that this box will display the currenty-selected cells?

How to&Answers:

We can make use of the Default property of the Inputbox method like this:

Set RangeDest = Application.InputBox("Select range to paste onto ", "Obtain Range Object", Selection.Address, Type:=8)

enter image description here