Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ADK ADK is offline
external usenet poster
 
Posts: 89
Default inputbox error when clicking cancel

If someone uses this code, but clicks cancle on the inputbox you get a code
error. What cacode can be added to prevent this error?

Sub SelectRange()
Dim UserRange As Range
Set UserRange = Application.InputBox( _
prompt:="Please input or select a range", Type:=8)
UserRange.Font.Bold = True
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 195
Default inputbox error when clicking cancel

ADK ,Check this out...
I think this a better solution as it overcomes some known bugs.

http://www.jkp-ads.com/Articles/SelectARange.asp

ADK wrote:
If someone uses this code, but clicks cancle on the inputbox you get a code
error. What cacode can be added to prevent this error?

Sub SelectRange()
Dim UserRange As Range
Set UserRange = Application.InputBox( _
prompt:="Please input or select a range", Type:=8)
UserRange.Font.Bold = True
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default inputbox error when clicking cancel

Sub SelectRange()
Dim UserRange As Range
On Error Resume Next
Set UserRange = Application.InputBox( _
prompt:="Please input or select a range", Type:=8)
On Error goto 0
if not userrange is nothing then
UserRange.Font.Bold = True
end if
End Sub

I have a little different take on this than Steve.
There are many many errors associated with the RefEdit control. Far more
than this error with Application.Inputbox. I would be more inclined to check
the sheet for a situation that uses the troublesome conditional formatting
and put up the inputbox when it isn't a problem.

--
Regards,
Tom Ogilvy


"ADK" wrote:

If someone uses this code, but clicks cancle on the inputbox you get a code
error. What cacode can be added to prevent this error?

Sub SelectRange()
Dim UserRange As Range
Set UserRange = Application.InputBox( _
prompt:="Please input or select a range", Type:=8)
UserRange.Font.Bold = True
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default inputbox error when clicking cancel

Sub SelectRange()
Dim UserRange As Range
On Error Resume Next
Set UserRange = Application.InputBox( _
prompt:="Please input or select a range", Type:=8)
If UserRange is Nothing then Exit Sub
UserRange.Font.Bold = True
On error Goto 0
End Sub

Charles Chickering
ADK wrote:
If someone uses this code, but clicks cancle on the inputbox you get a code
error. What cacode can be added to prevent this error?

Sub SelectRange()
Dim UserRange As Range
Set UserRange = Application.InputBox( _
prompt:="Please input or select a range", Type:=8)
UserRange.Font.Bold = True
End Sub


  #5   Report Post  
Posted to microsoft.public.excel.programming
ADK ADK is offline
external usenet poster
 
Posts: 89
Default inputbox error when clicking cancel

Ok, the error part seems to be set but the code is not using the selected
cell at the inputbox prompt ...it is using the cell row previous to the
macro run. help!

Private Sub InsertlineButton1_Click()
Dim CellOne As Range
On Error Resume Next
Set CellOne = Application.InputBox( _
prompt:="Please input or select a cell which will be the row below
the new inserted row", Type:=8)
If CellOne Is Nothing Then
MsgBox "It appears as if you pressed cancel!"
End If
If CellOne Is Nothing Then
Exit Sub
Else
Set CellOne = ActiveCell

If CellOne.Value = 1 Then

MsgBox "You can not insert a row above Number 1", 64, "Invalid"

Exit Sub

End If
Range("A" & ActiveCell.Row).Select
ActiveCell.EntireRow.Insert
ActiveCell.Offset(-1, 0).Select
Cells(ActiveCell.Row + 1, ActiveCell.Column).Select
Selection.FillDown
End If
End Sub

"stevebriz" wrote in message
oups.com...
ADK ,Check this out...
I think this a better solution as it overcomes some known bugs.

http://www.jkp-ads.com/Articles/SelectARange.asp

ADK wrote:
If someone uses this code, but clicks cancle on the inputbox you get a
code
error. What cacode can be added to prevent this error?

Sub SelectRange()
Dim UserRange As Range
Set UserRange = Application.InputBox( _
prompt:="Please input or select a range", Type:=8)
UserRange.Font.Bold = True
End Sub






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default inputbox error when clicking cancel

Your code is written to use the activecell and not the cell selected. The
Application.InputBox function does not change the activecell.

Private Sub InsertlineButton1_Click()
Dim CellOne As Range
On Error Resume Next
Set CellOne = Application.InputBox( _
prompt:="Please input or select a cell which will be" & _
"the row below the new inserted row", Type:=8)
If CellOne Is Nothing Then
MsgBox "It appears as if you pressed cancel!"
Exit Sub
Else
If CellOne.Value = 1 Then
MsgBox "You can not insert a row above Number 1", 64, "Invalid"
Exit Sub
End If
CellOne.EntireRow.Insert
CellOne.Offset(-1, 0).FillDown
End If
End Sub

--
Regards,
Tom Ogilvy






"ADK" wrote in message
...
Ok, the error part seems to be set but the code is not using the selected
cell at the inputbox prompt ...it is using the cell row previous to the
macro run. help!

Private Sub InsertlineButton1_Click()
Dim CellOne As Range
On Error Resume Next
Set CellOne = Application.InputBox( _
prompt:="Please input or select a cell which will be the row below
the new inserted row", Type:=8)
If CellOne Is Nothing Then
MsgBox "It appears as if you pressed cancel!"
End If
If CellOne Is Nothing Then
Exit Sub
Else
Set CellOne = ActiveCell

If CellOne.Value = 1 Then

MsgBox "You can not insert a row above Number 1", 64, "Invalid"

Exit Sub

End If
Range("A" & ActiveCell.Row).Select
ActiveCell.EntireRow.Insert
ActiveCell.Offset(-1, 0).Select
Cells(ActiveCell.Row + 1, ActiveCell.Column).Select
Selection.FillDown
End If
End Sub

"stevebriz" wrote in message
oups.com...
ADK ,Check this out...
I think this a better solution as it overcomes some known bugs.

http://www.jkp-ads.com/Articles/SelectARange.asp

ADK wrote:
If someone uses this code, but clicks cancle on the inputbox you get a
code
error. What cacode can be added to prevent this error?

Sub SelectRange()
Dim UserRange As Range
Set UserRange = Application.InputBox( _
prompt:="Please input or select a range", Type:=8)
UserRange.Font.Bold = True
End Sub






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
Cancel on INPUTBOX macro causes error Barb Reinhardt Excel Programming 7 January 21st 06 11:28 PM
InputBox Function & Cancel Otto Moehrbach[_6_] Excel Programming 4 September 30th 04 01:13 AM
Help with inputbox (Distinguish OK from Cancel) NooK[_47_] Excel Programming 3 August 5th 04 11:45 AM
Clicking Cancel on an Inputbox rott[_6_] Excel Programming 3 March 5th 04 02:57 AM
Inputbox and cancel button Uddinj1 Excel Programming 5 March 2nd 04 11:27 AM


All times are GMT +1. The time now is 03:11 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"