Calculating with workdays and extra days

Flash0220

Board Regular
Joined
May 2, 2002
Messages
104
Hello,


I'm using Excel 2003, and i'm having the following problem with calculating days.

A user will type a date in cel A1.
Now some calculating has to be done, and the result has to be placed in cell B1.

Let's say the value in cell A1 is november 1st 2011.

I now need VBA code which adds 10 days to that date.
The VBA code may not count weekends (saturdays and sundays) and may also not
add/calculate any "special" dates stored in a list on another tab/sheet with the name "Holidays" (range A10:A50).
For this example there are 2 dates (November 3rd and November 9th) which are in
that 10 day range and are in that list.

To the date to be calculated has to be november 17th 2011.

Is there a way to do this in Excel VBA 2003 ?

Thanks for helping. :-)


Flash0220
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Without VBA

=WORKDAY(A1,10,Holidays!A10:A50)

This requires the Analysis Toolpak from Tools > Add-ins.
 
Upvote 0
Hello,


Thanks for your fast reply. :-)

The problem is that my employer does not want a formula version, but
only a VBA version.

The formula version works fine, but unfortunately i need a VBA version. :-)


Best regards,
Flash0220
 
Upvote 0
Try like this

Code:
Sub test()
Range("B1").Value = Evaluate("WORKDAY(A1,10,Holidays!A10:A50)")
End Sub
 
Upvote 0
Hello,


Thanks again for the fast reply. :-)

I inserted your code in my program, modified it a little, but i now get an error.

' Collumn A is selected.

' Selecting the cell 3 positions to the right and store the value (a date) in "DateLetterSend".
ActiveCell.Offset(0, 3).Select
DateLetterSend = ActiveCell.Value

' Moving 1 cell to the right to get to the cell where the result has to be generated.
ActiveCell.Offset(0, 1).Select

' The VBA code which should generate the result.
ActiveCell.Value = Evaluate("WORKDAY(DateLetterSend,10,Holidays!A10:A50)")

When i run the code i get a "#NAME?" ("#NAAM?" in dutch Excel 2003 version) error.
I loaded the Analysis Toolpak add-in but i still get this error.

I can't figure out what's wrong with my code.

Can anyone help me out ?
Thanks :-)


Best regards,
Flash0220

(A not very experienced VBA user....)
 
Upvote 0
Try

ActiveCell.Value = Evaluate("WORKDAY(" & DateLetterSend & ",10,Holidays!A10:A50)")
 
Upvote 0
Hello,


ActiveCell.Value = Evaluate("WERKDAG(DateLetterSend,10,Holidays!A10:A50)")
also generates the "#NAAM?" error. :-(

The VBA editor recognises the "Evaluate" command as a VBA command, so that command
can not cause the error, as far as i know.

ActiveCell.Value = Evaluate("WERKDAG(" & DateLetterSend & ",10,Holidays!A10:A50)")
generates the "#NAAM" error.

ActiveCell.Value = Evaluate("WORKDAY(" & DateLetterSend & ",10,Holidays!A10:A50)")
generates a "#N/B" error.

Weird....


Best regards,
Flash0220
 
Upvote 0
Sorry, I don't know why it isn't working. It worked when I tested it.

Can you get the worksheet formula to work?
 
Upvote 0
Try adding quotes to the string like this:

Code:
Sub test()

    Dim DateLetterSend As Date
    DateLetterSend = ActiveCell.Offset(0, 3).Value
    
    ActiveCell.Offset(0, 4).Value = (Evaluate("WORKDAY(""" & DateLetterSend & """,10,Sheet2!A10:A50)"))

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,462
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top