Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Inputbox method using type:=8 - How to Cancel?

"Vasant Nanavati" wrote...
You need something like the following awkward construction:

Sub ForceRangeInput()
Dim vResp As Variant
Do Until TypeName(vResp) = "Range"
On Error Resume Next
Set vResp = Application.InputBox("Test", Type:=8)
On Error GoTo 0
Loop
vResp.EntireRow.Select
End Sub

It's tricky only because the InputBox can return two types, an object and a
boolean.

...

A variation: encapsulate the awkwardness in a function called by the procedure.

Sub foo()
Dim rng As Range
Set rng = InputRange(Prompt:="Select a range", Title:="foo", Force:=True)
If Not rng Is Nothing Then rng.EntireRow.Select
End Sub

Function InputRange( _
Optional Prompt As String = "", _
Optional Title As String = "", _
Optional Force As Boolean = False _
) As Range
'------------------------------------
Dim retry As Boolean

On Error Resume Next

Do
Set InputRange = Application.InputBox(Prompt:=Prompt, Title:=Title, Type:=8)

If InputRange Is Nothing And Force And Not retry Then
retry = True
Prompt = "YOU MUST SELECT A RANGE!" & Chr(13) & Prompt
End If
Loop While InputRange Is Nothing And Force

On Error GoTo 0
End Function

--
1. Don't attach files to postings in this newsgroup.
2. Snip unnecessary text from quoted text. Indiscriminate quoting is wasteful.
3. Excel 97 & later provides 65,536 rows & 256 columns per worksheet. There are
no add-ins or patches that increase them. Need more? Use something else.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Inputbox method using type:=8 - How to Cancel?

Nicely constructed, Harlan. :-)

Regards,

Vasant.

"Harlan Grove" wrote in message
...
"Vasant Nanavati" wrote...
You need something like the following awkward construction:

Sub ForceRangeInput()
Dim vResp As Variant
Do Until TypeName(vResp) = "Range"
On Error Resume Next
Set vResp = Application.InputBox("Test", Type:=8)
On Error GoTo 0
Loop
vResp.EntireRow.Select
End Sub

It's tricky only because the InputBox can return two types, an object and

a
boolean.

..

A variation: encapsulate the awkwardness in a function called by the

procedure.

Sub foo()
Dim rng As Range
Set rng = InputRange(Prompt:="Select a range", Title:="foo", Force:=True)
If Not rng Is Nothing Then rng.EntireRow.Select
End Sub

Function InputRange( _
Optional Prompt As String = "", _
Optional Title As String = "", _
Optional Force As Boolean = False _
) As Range
'------------------------------------
Dim retry As Boolean

On Error Resume Next

Do
Set InputRange = Application.InputBox(Prompt:=Prompt, Title:=Title,

Type:=8)

If InputRange Is Nothing And Force And Not retry Then
retry = True
Prompt = "YOU MUST SELECT A RANGE!" & Chr(13) & Prompt
End If
Loop While InputRange Is Nothing And Force

On Error GoTo 0
End Function

--
1. Don't attach files to postings in this newsgroup.
2. Snip unnecessary text from quoted text. Indiscriminate quoting is

wasteful.
3. Excel 97 & later provides 65,536 rows & 256 columns per worksheet.

There are
no add-ins or patches that increase them. Need more? Use something

else.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
inputbox type 64 (array) pete the greek Excel Discussion (Misc queries) 8 May 20th 23 11:44 AM
InputBox / VBA question ok = print, cancel = exit todd78 Excel Worksheet Functions 4 August 9th 07 04:42 PM
Detecting Cancel in an InputBox Method Connie Excel Discussion (Misc queries) 2 October 19th 06 01:32 PM
how do i cancel the type blocking in the cell? ashley New Users to Excel 1 June 30th 05 01:35 AM
Inputbox method using type:=8 - How to Cancel? Jim Cone Excel Programming 0 July 8th 03 06:15 PM


All times are GMT +1. The time now is 07:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"