Confusion with Application.InputBox types

I’ve read over the Microsoft explanation of Application.InputBox as well as some other websites, and from what I understand, type:=8 should return a range value, but only if you select multiple cells. Is there a way to get the range of a user selection for just a single cell?

Furthermore, I’ve used it in 2 situations and then used Intersect to make sure the user has selected a cell within a given range. The first use runs as intended, the second use produced “application defined or object defined error,” but the only differences between the two are the Application.InputBox title and the names of the variables set from Application.InputBox.

I have a feeling this error could be misleading, as there have been many times for example where I’ve forgotten to close an if statement but the error tells me the problem is with the while loop surrounding it. But I thought I’d put the problem up to see if anyone has an alternative method to obtain a single cell user selected range, and in the meantime I’ll look around the code of the second use to see if there is in fact something else that’s wrong.

First Use:

Dim shift_type_range As Range
Dim name As String

Set shift_type_range = Application.InputBox("Please select the shift type you would like to assign to " & name & "'s shift from the shift type key.", "Select Shift Type", Type:=8)
MsgBox shift_type_range ' outputs the value in the cell.
If Intersect(shift_type_range, Sheets("Rota Builder").Range("P21:P30")) Is Nothing Then ' If statement runs with no error
' the bulk in the if statement is irrelevant to the question.
End If

Second Use:

Dim staff_1 As Range
Set staff_1 = Application.InputBox("Please select the shift of the first member of staff.", "Select Shift", Type:=8)
MsgBox staff_1 ' Again, outputs the value in the cell.
If Intersect(staff_1, Sheets("Published Rota").Range("B7", "H" & b_last_row)) Is Nothing Then ' produced "application defined or object defined" error.
' the bulk in the if statement is irrelevant to the question.
End If

3

The Intersect method can works only if the two ranges are on the same sheet.
When your code execute the InputBox line, the default sheet is the active sheet. If you click a cell on it, and this sheet not corresponds to the other range’s parent sheet, an App runtime error is generated.
When you select the cell, first select the sheet (in the second case Published rota and then click on the cell you need.
The InputBox function works with one cell also. It is important that this is a Range object which is returned.
The b_last_row variable must contain a valid row value, otherwise an error is generated. (if <1, or greater then the max. number of rows of the excel application.

New contributor

Balázs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật