View Single Post
  #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