Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Input box cancel produces error

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Input box cancel produces error

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

--
Regards,
Tom Ogilvy

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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Input box cancel produces error

Try using vbYes and vbNo. If youg get vbNo, then exit sub



"pkeegs" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Input box cancel produces error

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 Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy

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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Input box cancel produces error

Tom does that later with activecell.value.

Are you sure that there is a single cell named BalanceDate?



pkeegs wrote:

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 Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy

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





--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Input box cancel produces error

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

"Dave Peterson" wrote:

Tom does that later with activecell.value.

Are you sure that there is a single cell named BalanceDate?



pkeegs wrote:

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 Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy

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




--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Refresh produces #N/A error RhysPieces Links and Linking in Excel 1 July 11th 07 07:42 PM
Refresh produces #N?A error RhysPieces Excel Discussion (Misc queries) 1 July 10th 07 09:16 AM
Input Box - CANCEL Danny Excel Worksheet Functions 6 December 1st 06 02:15 AM
cancel input ME @ Home Excel Discussion (Misc queries) 1 February 22nd 06 09:49 AM
CreateObject produces error Robert Chapman Excel Programming 0 August 15th 03 03:48 PM


All times are GMT +1. The time now is 10:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"