VBA InputBox user select range with reference

nd0911

Board Regular
Joined
Jan 1, 2014
Messages
166
Hello,

I want to let the user to select a range with reference of his choice.

I have this line of code

VBA Code:
Set Rng = Application.InputBox(MyMsg, , , , , , , 8)

When the inputbox is shown the user can press F4 key to change the reference type to what he want, but how can I get the reference type ?
 
A range does not have a reference type, a range address has a reference type.
An input box with type:=8 returns a range, not a range address. The dialog box will show the range's address (with the absoute/reative addressing controled by F4), but what is returned is the range that the user selected, not the address.
Ranges do not have reference styles. Range addresses have reference styles. An InputBox with type:=8 does not return range addresses.
Yes I know that, so what I need is to get the user range as a string with the reference type.
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
find a solution:

VBA Code:
str = Application.InputBox("bla bla", , , , , , , 0)
str = Application.ConvertFormula(str, xlR1C1, xlA1)
 
Upvote 0
I am not sure why you showed that last code line as it is converting a formula in R1C1 notation to A1 notation which is not what you described you wanted to do. Assuming your written description is actually what you want to do, see if the example macro does what you want...
VBA Code:
Sub Test()
  Dim Rng As Range, Txt As String
  Set Rng = Application.InputBox("Please select a range..", Type:=8)
  Txt = InputBox("Please remove $ sign from any refrence that should be relative...", , Rng.Address)
  
  MsgBox Txt
  
End Sub
 
Upvote 0
I noticed that the type of the input box changed to 0, which is great for entering formulas and where the F4 key for abs/rel is relevant. And it provides a string that can be used by ConvertFormula.
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,361
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top