Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limit user selected range to one row

Status
Not open for further replies.

JTBorton

Technical User
Jun 9, 2008
345
DE
I have a situation where I need the user to select one row - just one. I am using the inputbox type 8 to allow the user to select the range, then I test to see if they selected more than one row. However, it seems when they select only one row, or even just one cell, it returns a range of rows. Can anyone help me find a better way to do this?

Excel 2003 Prof.

Code:
Dim rngSource   As Range
Dim Catch       As String
Dim Row         As Integer
Dim Response    As Integer
GetCell:
    On Error Resume Next
    Set rngSource = Nothing 'Clear the rang incase the user was redirected here and now wishes to cancel
    Set rngSource = Application.InputBox(prompt:="Please select the cell that contains the name of the product you wish to remove.", Title:=strTitle, Type:=8)
    If rngSource Is Nothing Then
        Exit Sub 'user selected cancel
    End If
    On Error GoTo 0
    If Not rngSource.End(xlDown).Row = rngSource.End(xlUp).Row Then
        Response = MsgBox(prompt:="Please select a cell from only one row, not a range of cells.", Buttons:=vbExclamation + vbOKCancel, Title:=strTitle)
        If Not Response = vbOK Then
            Exit Sub
        Else
            GoTo GetCell
        End If
    End If
    Row = rngSource.End(xlDown).Row

-JTBorton
Well, You can try banging your head against the wall, but you just end up with lost-time injuries and damaged equipment. [M. Passman]
 


Hi,
Code:
[s]
If Not rngSource.End(xlDown).Row = rngSource.End(xlUp).Row Then[/s]
If rngSource.rows.count > 1 Then


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Ah that does it. Thanks again Skip.

-JTBorton
Well, You can try banging your head against the wall, but you just end up with lost-time injuries and damaged equipment. [M. Passman]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top