+ Reply to Thread
Results 1 to 4 of 4

simply formula by writing it in VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    09-03-2004
    Posts
    7

    simply formula by writing it in VBA

    Hi there,

    I have written a series of formulas in an excel workbook and need to consolidate the steps.

    What the formulas do is look up the value in B1 and if the date in cell "A1" is less than the first Tuesday of the month, then this cell should have First Tuesday of the month else it should have the first Tuesday of the next month.

    Currently this is part of a really big spreadsheet so I would prefer it to only be the vlookup and one other cell.

    I have attached the spreadsheet and would be very grateful if someone could suggest either some vba code to simplify the process or help me create a nested formula to consolidate all the steps.

    thanks
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    06-10-2004
    Location
    India
    Posts
    1,066
    Use the following formula:

    =IF(AND(DAY(A1)<8,(DAY(A1)-WEEKDAY(A1)>0)),DATE(YEAR(A1),MONTH(A1),DAY(A1)-WEEKDAY(A1)+3),DATE(YEAR(EOMONTH(A1,0)+1),MONTH(EOMONTH(A1,0)+1),DAY(EOMONTH(A1,0)+1)-WEEKDAY(EOMONTH(A1,0)+1)+3))

    Note: You require the addin Analysis Toolpak for this as I am using EOMONTH function

    Breaking up the formula for readability

    =IF(AND(DAY(A1)<8,(DAY(A1)-WEEKDAY(A1)>0)),DATE(YEAR(A1),MONTH(A1),DAY(A1)-WEEKDAY(A1)+3),
    DATE(YEAR(EOMONTH(A1,0)+1),MONTH(EOMONTH(A1,0)+1),DAY(EOMONTH(A1,0)+1)-WEEKDAY(EOMONTH(A1,0)+1)+3))



    - Mangesh

  3. #3
    Registered User
    Join Date
    09-03-2004
    Posts
    7

    thank you!

    thank you! a great way of doing this!

  4. #4
    Forum Contributor
    Join Date
    06-10-2004
    Location
    India
    Posts
    1,066
    Also note that, if you need any other day (other than tuesday), you just have to substitute the 3 in the formula with the weekday of the required day.

    - Mangesh

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1