+ Reply to Thread
Results 1 to 9 of 9

VBA Calculate Working Number of Days

  1. #1
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    VBA Calculate Working Number of Days

    Hi, I wonder whether someone could help me please.

    I'm using the following sheet layout to display staff resource detail
    COLUMN B COLUMN C COLUMN D COLUMN E COLUMN F COLUMN G COLUMN H COLUMN I COLUMN J COLUMN K COLUMN L COLUMN M COLUMN N COLUMN O COLUMN P COLUMN Q
    ROW 3 22 23 20 23 22 21 23 21 22 23 20 21
    ROW 4 Description Apr-13 May-13 Jun-13 Jul-13 Aug-13 Sep-13 Oct-13 Nov-13 Dec-13 Jan-14 Feb-14 Mar-14 Actual Hours Total Mandays Total FTE Total
    ROW 5 Project 1 1155.14 1463.71 1615.53 1333.76 232.01 32.05 NEW FORMULA

    What I'm trying to do, is add a formula via VBA in the "FTE" column (Labelled as NEW FORMULA in the above table), which performs the following:

    • Search row 4 in columns C:N and find the month which matches the current month.
    • When a match is found, take the corresponding value from row 3 and multiply this value by the value in column P.
    • So using the above as an example, the formula in column Q on row 5, would be 22 (Because we are in August) multiplied by 32.05 (Cell P5) giving a total of 705.10.

    I've attached a file which perhaps illustrates this better than I can explain, and I've started the code in VB editor, but it's just the formula that I'm having difficulty in working out.

    I just wondered whether someone could look at this please and offer some guidance on how I may go about achieving this.

    Many thanks and kind regards
    Attached Files Attached Files
    Last edited by hobbiton73; 08-31-2013 at 08:49 AM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,962

    Re: VBA Calculate Working Number of Days

    The workbook you posted does not match the description in post #1
    Ben Van Johnson

  3. #3
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Calculate Working Number of Days

    Hi @protonLeah, thank you very much for taking the time to reply to my post and please accept my sincere apologies for the error.

    I've now corrected the text in my original post which should now match my file.

    Many thanks and kind regards

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Calculate Working Number of Days

    Hi Chris,
    Try the attached.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Calculate Working Number of Days

    Hi AB33, it's nice to hear from you.

    Thank you for taking the time to reply to my post and for the solution.

    The code works great, but could you perhaps tell me please how I may change the code so that the formula is applied to every row within column Q if there is a value in column P of the same row.

    My sincere apologies if I didn't make this clear in my original post.

    Many thanks and kind regards

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Calculate Working Number of Days

    Amended!
    I think you would be better off with formula.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Calculate Working Number of Days

    Hi @AB33, thank you very much for coming back to me so quickly with this, it's greatly appreciated.

    May I ask please, would it be at all possible to remove the zero from the final row. For example, on the "Projects" sheet in the file you kindly posted this is row 9.

    Could I also ask please, could you include some annotation to the code, so I can learn what is happening within the script.

    Many thanks and kind regards

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Calculate Working Number of Days

    If the code works, close it and will PM you for explanation.

    Change this line

    Please Login or Register  to view this content.
    INTO
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Calculate Working Number of Days

    Hi AB33, thank you very much for coming back to me with this, it's works perfectly.

    Thank you very much for all your time and trouble.

    Kind Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Calculate the number days between two user input days.
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-21-2013, 10:44 PM
  2. Calculate total working days and excepted leave days
    By megaiooo in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-21-2013, 09:29 AM
  3. Need to calculate working days
    By bryanshiva in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-12-2013, 07:47 AM
  4. calculate net working days
    By mpkishore in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-01-2007, 07:17 AM
  5. calculate number of working days
    By philc in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-06-2005, 03:05 AM

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