MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 26th, 2002, 11:06 AM   #1
Happy_Dog
New Member
 
Join Date: Apr 2002
Posts: 16
Default

How can I call a vba function that I can use like the built in functions? for example I need the number of weekdays between two dates, similar to =DAYS360() which returns total number of days.
Happy_Dog is offline   Reply With Quote
Old Apr 26th, 2002, 11:13 AM   #2
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

Theoretically you can use the worksheetfunction class, but it was misfiring on my pc. So I settled on:

Code:
MsgBox Evaluate("=DAYS360(TODAY(),TODAY()-1)")
__________________
Regards,
Nate Oliver
Microsoft Excel MVP
Nate's Excel Blog
NateO is offline   Reply With Quote
Old Apr 26th, 2002, 11:22 AM   #3
Happy_Dog
New Member
 
Join Date: Apr 2002
Posts: 16
Default

Thanks for the quick reply, but I'm not sure we're on the same track. I have created a function for the worksheet called GetWorkDays that takes two parameters, start date and end date. In a cell I want to do something like =GetWorkDays(4/26/2002,5/26/2002) and get the result in the cell.
Happy_Dog is offline   Reply With Quote
Old Apr 26th, 2002, 11:24 AM   #4
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

Oh. Whoops . Sorry 'bout the misread, see

=Networkdays()

_________________
Cheers, NateO

[ This Message was edited by: NateO on 2002-04-26 10:38 ]
NateO is offline   Reply With Quote
Old Apr 26th, 2002, 11:27 AM   #5
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

You would do something like this:


Public Function GetWorkDays (ByVal oStartDate As Date,ByVal oEndDate as Date)

'Your code using oStartDate and oEndDate as you variables and then finally set GetWorkDays equal to your answer e.g.:

GetWorkDays = oEndDate - oStartDate 'Would give you the time between your dates

End Function


To use this in your worksheet you would simply put in a cell:

=GetWorkDays(4/26/2002,5/26/2002)

HTH
__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien is offline   Reply With Quote
Old Apr 26th, 2002, 11:31 AM   #6
Robb__
New Member
 
Join Date: Apr 2002
Posts: 41
Default

Happydog

You don't really need to create a function for use in the worksheet. Use Networkdays.

You do, however, need to have the Analysis Toolpak installed. To do this select Tools/AddIns and then select Analysis Toolpak.

Once this is done, you will be able to us e the Networkdays function.

Say you have a dtae in A1 and another in A2, in A3 enter =Networkdays(A1,A2) and the result will be the number of workdays between the two (A1 is start, A2 is end). If you want to range over a persiod containing public holidays, you may also allow for them. List the holidays, say in H1 to H5, the formula then becomes =Networkdays(A1,A2,H1:H5).

Any help?

Regards

Robb__
Robb__ is offline   Reply With Quote
Old Apr 26th, 2002, 11:33 AM   #7
Happy_Dog
New Member
 
Join Date: Apr 2002
Posts: 16
Default

Nate/Robb, I am looking into that as a possible solution. Will this work for other users if they do not have the Analysis ToolPak installed?

Mark, I tried this and it does not seem to work for me. I'm just getting the #NAME?

Thanks.
Happy_Dog is offline   Reply With Quote
Old Apr 26th, 2002, 11:34 AM   #8
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

Also take note, if you want to hard code the date's you'll need to do so using Excel's date serial number methodology, which is quite a bit of fun.

I didn't realize this function was of the analysis toolpak variety. It comes with XL, just go tools->add ins, check the appropriate box and you're in like a dirty shirt, others should replicate this procedure...
_________________
Cheers, NateO

[ This Message was edited by: NateO on 2002-04-26 10:37 ]
NateO is offline   Reply With Quote
Old Apr 26th, 2002, 11:39 AM   #9
Happy_Dog
New Member
 
Join Date: Apr 2002
Posts: 16
Default

All right that will work then.
Thanks everyone.
Happy_Dog is offline   Reply With Quote
Old Apr 26th, 2002, 11:40 AM   #10
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

Quote:
Mark, I tried this and it does not seem to work for me. I'm just getting the #NAME?

Thanks.
Probably because I just typed this one in the board and didn't test it, sorry. If you're interested I'll knock it up later, but it seems like there's a solution for you.

Take it easy.

__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 05:28 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes