Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Works fine in debug, but...

Hi all,

I can't get my head around why this simple piece of code won't work in
release, but does in step-by-step debugging. This code is part of a
userform with two calendars on it.

Ideas anyone?

p.s. I'm guessing the Analysis Toolpack function "networkdays" is the
cause, but why?

Private Sub CalendarEnd_Click()

Dim sDay As Date
Dim eDay As Date
Dim nwDays As Integer

On Error GoTo Skip
sDay = CalendarStart.Value
eDay = CalendarEnd.Value

nwDays = networkdays(sDay, eDay)
If nwDays < 1 Then GoTo Skip
UserForm2.TextBox2.Value = nwDays

Exit Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Works fine in debug, but...


A classic problem that is evidenced by code working when in debug but
not when run straight through is that there are other process that need
to be given processor time to complete. To do this programmatically you
use the doevents. Finding whereto put it is a bit more difficult but
with this short piece of code you could put a doevents between each
line.

If that works you could try removing them one by one until it goes
wrong again then you will know which is the important one (or more).

Hope this helps. let us know how you get on.

regards,
Anthony


--
tony h
------------------------------------------------------------------------
tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074
View this thread: http://www.excelforum.com/showthread...hreadid=516141

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Works fine in debug, but...

Anthony ,
Thanks for the suggestions.
Tried this, no joy.

I've determined that the line nwDays = Networkdays(sDay, eDay) is
causing the error, Runtime 13, type mismatch.

I've tried other otions, like

eDay = CDate(eDay) and
eDay = Format(eDay, "dd/mm/yyyy")

and also tried Variant, Long etc. for the nwDays variable

Any other suggestions are more than welcome.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Works fine in debug, but...

Are you sure sDay & eDay both evaluate to +ve numbers

try
nwDays = networkdays(Date, Date + 21)

Regards
Peter T


"DiBaco" wrote in message
ups.com...
Anthony ,
Thanks for the suggestions.
Tried this, no joy.

I've determined that the line nwDays = Networkdays(sDay, eDay) is
causing the error, Runtime 13, type mismatch.

I've tried other otions, like

eDay = CDate(eDay) and
eDay = Format(eDay, "dd/mm/yyyy")

and also tried Variant, Long etc. for the nwDays variable

Any other suggestions are more than welcome.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Works fine in debug, but...

sorry to say, same error

tries switching values with
If eDay < sDay Then

and If eDay sDay Then

same error.

will try to build something from scratch and see what happens..

Thanks for your efforts



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Works fine in debug, but...

building from scratch doesn't give the error.... weird

guess I'll have to redo the whole thing...

:-(

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
VBA errors in 2007 (works fine in 2003) Horatio J. Bilge, Jr. Excel Discussion (Misc queries) 14 September 6th 09 12:46 PM
Macro hangs up often but sometimes works fine Jeff Excel Worksheet Functions 3 June 13th 06 01:01 PM
VLOOKUP on separate file: Works fine for a while.... Ken Cobler Excel Worksheet Functions 0 September 16th 05 05:18 PM
VBA problem, works fine as formula but not in VBA Xlund Excel Programming 4 April 13th 04 10:57 AM
Macro works fine in xl2002 but does not in xl 2000 Nolin[_2_] Excel Programming 1 February 25th 04 05:58 PM


All times are GMT +1. The time now is 02:08 AM.

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

About Us

"It's about Microsoft Excel"