View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
StargateFan[_3_] StargateFan[_3_] is offline
external usenet poster
 
Posts: 171
Default "OnCancel" syntax?

Some syntax given to me has error handling but I've found that that
doesn't work in a situation where the user can choose to cancel.
Cancelling while performing an operation just causes the process to
loop back so, in essence, the user is forced to continue.

Can an additional option for when a user hits cancel be added to this
great script (courtesy of JulieD; thanks Julie! <g). The error part
doesn't handle a cancel by the user.

------------------------------------------------------------------------------------------------
Sub insertrows()

Dim i As Long
Dim j As Long
Dim k As Long

On Error GoTo dontdothat
Do
i = InputBox("How many rows do you want to insert?", "Insert
Rows",
1)
Loop Until i < 0
Do
j = InputBox("At what row number do you want to start the
insertion?", "Insert Rows", 1)
Loop Until j < 0

ActiveSheet.Unprotect
k = j + i - 1
Range("" & j & ":" & k & "").Insert shift:=xlDown
j = j - 1
Range("A" & j & "").Select
Selection.AutoFill Destination:=Range("A" & j & ":A" & k &
""),
Type:=xlFillDefault
ActiveSheet.Protect
Exit Sub

dontdothat:
Resume

End Sub
------------------------------------------------------------------------------------------------

Thanks!