Restrict range in input box

elm

New Member
Joined
Feb 15, 2008
Messages
21
I have an input box that requires user input of a cell range. The columns are always the same eg. D:H. These columns cannot be varied. The row numbers do vary. Can anyone please tell me how to restrict entry to (for example) D50:H80 or D150:H250. Thanks in advance,
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I have an input box that requires user input of a cell range. The columns are always the same eg. D:H. These columns cannot be varied. The row numbers do vary. Can anyone please tell me how to restrict entry to (for example) D50:H80 or D150:H250. Thanks in advance,
Are you using the Application.InputBox (with the Type equal to 8) or are you using VB's InputBox where the user types in an address?

Also, if the user specifies an incorrect range, do you want the range automatically adjusted using the specified rows from the incorrect range or do you want an error message issued?
 
Upvote 0
Application.Inbox With Type 8. If incorrect range, an error message. Thanks
 
Upvote 0
Application.Inbox With Type 8. If incorrect range, an error message.
Structure your code similar to how I do it in the example code below...
Code:
Sub Test()
  Dim Rng As Range
  On Error GoTo NoRangeSelected
  Set Rng = Application.InputBox("Select range spanning Columns D:H.", Type:=8)
  If Rng(1).Column <> 4 Or Rng.Columns.Count <> 5 Then
    MsgBox "You selected range """ & Rng.Address(0, 0) & """ which does not span Columns D:H!", vbCritical
  Else
[COLOR="#008000"]    '
    ' The selected range is good, so do whatever you want with it here
    '[/COLOR]
  End If
  Exit Sub
NoRangeSelected:
  MsgBox "No range selected!", vbCritical
End Sub
 
Upvote 0
Thanks so much Rick. Exactly what I need. Thank you for taking the time to help me out
Regards, Rob
 
Upvote 0

Forum statistics

Threads
1,216,067
Messages
6,128,590
Members
449,461
Latest member
jaxstraww1

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