Input box cancel produces error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following to insert a date into the active cell. It works all
right to enter the default or a new date with OK, but when Cancel is clicked
it only produces an error. What do I need to exit the sub.

ActiveCell.Value = CDate(InputBox("Enter the end date of the period.", _
strTitle, Range("BalanceDate").Value))

Regards
 
Dim s as String
s = InputBox("Enter the end date of the period.", _
strTitle, Range("BalanceDate").Value)
if s <> "" then
if isdate(s) then
ActiveCell.Value = cdate(s)
else
Msgbox "Bad data"
end if
end if
 
Thanks Tom
I copied your code into a test macro but when I ran it, it stopped at
"s=InputBox...." Should there be a reference to the cell where value is
being inserted?
 
Tom does that later with activecell.value.

Are you sure that there is a single cell named BalanceDate?
 
Hi Dave & Tom,
message to all us amateurs "When you set up a test sheet to test code that
is proposed, don't forget to define the names that have been used!!!" It
works well.

Thanks very much

Regards
 

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

Similar Threads


Back
Top