Find next "dddd" based on formula in VBA

domtrump

Board Regular
Joined
Apr 1, 2010
Messages
245
I have a certain task that, depending on the day of the week that it is assigned, is always due either the upcoming Friday or the Following Wednesday. For example, if it is assigned on a Monday, it is due that Friday. If it assigned on a Thursday, it is due the following Wednesday. Here is the formula I use:

=IF(WEEKDAY(E3)=7,E3+6,IF(WEEKDAY(E3)=1,E3+5,IF(WEEKDAY(E3)=2,E3+4,IF(WEEKDAY(E3)=3,E3+3,IF(WEEKDAY(E3)=4,E3+7,IF(WEEKDAY(E3)=5,E3+6,IF(WEEKDAY(E3)=6,E3+5)))))))

I'd like to know how to write this formula (or a less complicated equivelent) using VBA so that I can incorporate it in a UserForm or other Macros.

Any suggestions? Thanks.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Here's a shorter version of your formula...
=E3+CHOOSE(WEEKDAY(E3),5,4,3,7,6,5,6)

Here's example code to use that formula in VBA. There are several ways this could be done though.
Code:
     Dim cel As Range, DueDate As Date
     
     Set cel = Sheets("Sheet1").Range("E3")
     
     DueDate = cel.Value + WorksheetFunction.Choose(WeekDay(cel.Value), 5, 4, 3, 7, 6, 5, 6)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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