[VBA] Inputbox Method Type 8, but with ENTIRE ROW/COLUMN constraint

oyy5408

New Member
Joined
Sep 12, 2014
Messages
3
Hi,

I'm trying to prompt user to select cells, but only allow them to select entire column(or row), like the embedded options of "print titles".
I would like to be able to do this with inputbox, but if not possible, any other solutions are welcome.

Thanks!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Code:
Sub checkSelection()



    If Selection.Count = ActiveSheet.Columns.Count Or Selection.Count = ActiveSheet.Rows.Count Then
        MsgBox "WE ALL GOOD SON"
    Else
        MsgBox "TRY AGAIN"


    End If


End Sub
 
Upvote 0
I would just modify the selection after the fact.

Code:
Sub test()
Dim x As Range
On Error Resume Next
Set x = Application.InputBox("Select Row", Type:=8)
If x Is Nothing Then Exit Sub
Set x = x.EntireRow
x.Select
End Sub
 
Upvote 0
Thanks for the codes, however, it is much more intuitive for the users if it worked EXACTLY like the "print titles" option, only allowing them to select by either rows or columns.
The cursor actually changes its icon to black arrow pointing to the right (something like this →) when I try to select the title rows, which is different from typical cell selector. Could that be a hint that Excel actually employs a different method instead of using "inputbox" method?

Thanks,
 
Upvote 0
I think you're thinking of a RefEdit Control on a UserForm. See here for information: XL2000: How to Use the RefEdit Control with a UserForm

You'll have to build a check in either way. YOu might also be able to take ideas from the code below.

However, here is some InputBox code that might help you.

Code:
Sub test()
Dim x As Range
Do
Set x = Application.InputBox("X", Type:=8)
Loop Until x.Columns.Count = Columns.Count Or x.Rows.Count = Rows.Count
End Sub
 
Upvote 0
I think you're thinking of a RefEdit Control on a UserForm. See here for information: XL2000: How to Use the RefEdit Control with a UserForm

You'll have to build a check in either way. YOu might also be able to take ideas from the code below.

However, here is some InputBox code that might help you.

Code:
Sub test()
Dim x As Range
Do
Set x = Application.InputBox("X", Type:=8)
Loop Until x.Columns.Count = Columns.Count Or x.Rows.Count = Rows.Count
End Sub
What about like this instead where if a partial range is selected, it is expanded in the natural direction...
Code:
Sub test()
  Dim Rng As Range
  On Error GoTo NothingSelected
  Set Rng = Application.InputBox("X", Type:=8)
  If Rng.Rows.Count > Rng.Columns.Count Then
    Rng(1).EntireColumn.Select
  Else
    Rng(1).EntireRow.Select
  End If
NothingSelected:
End Sub
 
Last edited:
Upvote 0
That's similar to where I was going with my first post, the op didn't like that idea.
 
Upvote 0
it is much more intuitive for the users if it worked EXACTLY like the "print titles" option, only allowing them to select by either rows or columns.
I think you'd need a RefEdit control on a userform to do that.
 
Upvote 0
As suggested, I tried playing around with the RefEdit control, but it seems it is more trouble than it's worth, so I decided to use Scott's code above.

Thank you!

I think you're thinking of a RefEdit Control on a UserForm. See here for information: XL2000: How to Use the RefEdit Control with a UserForm

You'll have to build a check in either way. YOu might also be able to take ideas from the code below.

However, here is some InputBox code that might help you.

Code:
Sub test()
Dim x As Range
Do
Set x = Application.InputBox("X", Type:=8)
Loop Until x.Columns.Count = Columns.Count Or x.Rows.Count = Rows.Count
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,257
Members
449,075
Latest member
staticfluids

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