View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
StargateFanFromWork StargateFanFromWork is offline
external usenet poster
 
Posts: 27
Default "OnCancel" syntax?

"StargateFan" wrote in message
...
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.


[snip]

Here's the code that seems to be working perfectly!

Column A has =ROW()-1 in it. This macro (thanks to JulieD for this great
code) will insert however many lines user requests into spot user says with
that column in the cell(s) in column A. Or if user realizes at any point
that s/he needs to cancel, it just stops the operation. Really neat stuff!
(Unprotect/protect code taken out because I'll be leaving the workbooks
unprotected as too many problems occurred with unavailable functionality.)

----------------------------------------------------------------------------
--------------
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", 10)
Loop Until j < 0

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
Exit Sub

dontdothat:

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