vb cancel button

  • Thread starter Thread starter kckar
  • Start date Start date
K

kckar

i am trying to find out what to write so that when you hit the cancel
button on the input box, nothing else happens. the cancel box will go
away.

here is my code


Dim deleteline As Integer
Dim count As Integer
count = 1
deleteline = InputBox("Enter Item Line to Delete")
Do While Range("f8").Offset(deleteline + count - 1) > 0
Range("g8").Offset(deleteline + count - 1, 0) =
Range("g8").Offset(deleteline + count, 0)
Range("i8").Offset(deleteline + count - 1, 0) =
Range("i8").Offset(deleteline + count, 0)
count = count + 1
Loop
Range("f8").Offset(deleteline + count - 1, 0) = ""
Range("a1") = Range("a1") - 1
Range("f8").Offset(Range("a1") + 1, 0) = ""
 
Add a test to the value of deleteline. Something like the following code.
(Just as an aside don't use "count" as a variable as it is a reserved word.
Use something like iCount or intCount. While in this case count probably
won't hurt you it won't help and it is a really bad habit to get into.)

Dim deleteline As Integer
Dim count As Integer
count = 1
deleteline = InputBox("Enter Item Line to Delete")
if deleteline = "" then exit sub
Do While Range("f8").Offset(deleteline + count - 1) > 0
Range("g8").Offset(deleteline + count - 1, 0) =
Range("g8").Offset(deleteline + count, 0)
Range("i8").Offset(deleteline + count - 1, 0) =
Range("i8").Offset(deleteline + count, 0)
count = count + 1
Loop
Range("f8").Offset(deleteline + count - 1, 0) = ""
Range("a1") = Range("a1") - 1
Range("f8").Offset(Range("a1") + 1, 0) = ""
 
Use Application.InputBox instead of just InputBox, and you'll get
a value of False returned if the user hits Cancel (or the Escape key).

See the Excel Help on InputBox for the subtle distinction between
these two.

hth
Andrew Taylor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top