![]() |
Application.InputBox error trapping
I have the following inputbox and need to trap erros
Set Rng= Application.InputBox(Msg1, Title1, Type:=8) where Rng is dimmed as an object 1) how do I trap the user response if they click cancel 2) how do i tarp the user response if the click Enter without selecting a range |
Application.InputBox error trapping
Does this help?
Sub TestIt() Dim Rng As Object ' On Error GoTo Bad_Rng Set Rng = Application.InputBox(Msg1, Title1, Type:=8) On Error GoTo 0 ' MsgBox "Got to here" Exit Sub ' Bad_Rng: MsgBox "Cancel button was pressed" End Sub If the user clicks enter and the box is blank, or has a badly formed range in it, then the InputBox Method itself displays a warning message and doesn't let the user get away with it. The only two ways for the user to get out are to enter a valid range, or to press Cancel. You can trap Cancel by doing what I did above. Eric |
Application.InputBox error trapping
I'd probably do it this way
Sub TestIt() Dim Rng As Object ' Set Rng = Nothing On Error Resume Next Set Rng = Application.InputBox(Msg1, Title1, Type:=8) On Error GoTo 0 ' If Rng Is Nothing Then MsgBox ("No range was selected.") End If End Sub -- HTH, Barb Reinhardt If this post was helpful to you, please click YES below. "egun" wrote: Does this help? Sub TestIt() Dim Rng As Object ' On Error GoTo Bad_Rng Set Rng = Application.InputBox(Msg1, Title1, Type:=8) On Error GoTo 0 ' MsgBox "Got to here" Exit Sub ' Bad_Rng: MsgBox "Cancel button was pressed" End Sub If the user clicks enter and the box is blank, or has a badly formed range in it, then the InputBox Method itself displays a warning message and doesn't let the user get away with it. The only two ways for the user to get out are to enter a valid range, or to press Cancel. You can trap Cancel by doing what I did above. Eric |
All times are GMT +1. The time now is 05:21 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com