+ Reply to Thread
Results 1 to 11 of 11

VBA Sum Figure With Dates That Match Column Headings

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

    VBA Sum Figure With Dates That Match Column Headings

    Hi, I wonder whether someone may be able to help me please.

    I'm trying to put together a script which performs the following:

    • Compare the column date headings on the "Output" sheet with the dates in column D on the "In Flight Projects" sheet.
    • If they match and the value in column C on the "In Flight Projects" sheet is "C&R", then
    • Sum the figures in column E on the "In Flight Projects" sheet and,
    • Paste the figure under the relevant column heading in row 8 on the "Output" sheet.

    I do have some VBA knowledge but sadly it's certainly lacking when it come to something as complicated as this.

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

    I appreciate that my description may not be the most clear, so I have attached a file which can hopefully illustrate this a little better.

    It contains three sheets, the "In Flight Projects" data sheet, the "Output" sheet and the "desired Output" sheet which shows how I'd like the results to be displayed.

    Many thanks and kind regards
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA Sum Figure With Dates That Match Column Headings

    Hi,

    Assuming you have Excel 2007 or later then
    C8 copied across

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    But also note that there is an inconsistent mixture of 'dates' on the In Flight projects sheet. Most are date numbers which evaluate to dates proper e.g. 1/10/2014, others are simply text strings like "Oct 14". You'll need to make them all consistent.

    For Excel 2003 you'll need to use a Sumproduct equivalent e.g.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

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

    Re: VBA Sum Figure With Dates That Match Column Headings

    Hi @Richard Buttery, thank you for taking the time for replying to my post.

    Unfortunately, although I use the 2013 version at home , I'm using 2003 at work, so the second option would be better.

    However I was really looking, if at all possible for a VB solution because this is being built as part of a bigger VB project which I've already written. It is also being used by users who are perhaps not quite as well versed in the use of Excel, so I thought a VB solution would be the simpler option.

    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 Sum Figure With Dates That Match Column Headings

    Christ,
    I have hard time formatting your dates(Date is my favourite topic in excel). Jan 15 is recognised as Jan-14. To make life simple, I have to manually change some of the data in to dates. So, if you do not get any match, it is because of the date format.
    I am off to watch Messi
    Attached Files Attached Files

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA Sum Figure With Dates That Match Column Headings

    You can of course use the SUMPRODUCT() approach in VB.

    Either use it with
    Please Login or Register  to view this content.
    syntax to add the value to the appropriate cell, or get VB to write the formula to the cell and immediately copy and then paste it back as a value.

    They both achieve the same end result.

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

    Re: VBA Sum Figure With Dates That Match Column Headings

    Hi AB33, thank you so much for taking the time to reply to my post andfor putting the solution together

    The code does work, but I'm unable to find a piece of code which stipulates that the value in column C on the "In Flight Projects" sheet must be "C&R", unless I'm missing something. It's just that when I implement his in live, there will be a number of values in this column which I need to differentiate from.

    Many thanks and the kindest regards

    Chris
    Last edited by hobbiton73; 04-10-2014 at 01:44 AM.

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

    Re: VBA Sum Figure With Dates That Match Column Headings

    Hi @Ruchard Buttery, thank you for this.

    I've used the Sumproduct function before, but I wasn't aware you could incorporate this into VB.

    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 Sum Figure With Dates That Match Column Headings

    Hi Chris,
    If you want to only consider cells which have C&R in column "C". If this does not give the correct result, I need to re-work the code.
    Attached Files Attached Files

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

    Re: VBA Sum Figure With Dates That Match Column Headings

    Hi @AB33, thank you very much for coming back to me with this.

    My apologies I thought I'd made this clear in my original post. Yes, it will only be for those records where the value in column C is "C&R".

    Many thanks and kind regards

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

    Re: VBA Sum Figure With Dates That Match Column Headings

    Chris,
    Yes, I missed that bit and have amended it.
    Have you tried post #8?

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

    Re: VBA Sum Figure With Dates That Match Column Headings

    Hi @AB33, thank you for coming back to me with this, it is truly appreciate and it's absolutely no problem at all re. the "C&R" value.

    I've tried the code and it works perfectly, thank you!

    May I ask please, if you could possibly add some notes to the code. As always these have always been extremely helpful in expanding my knowledge.

    Many thanks and kind regards

    Chris

+ 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. Macro to match column headings and paste into next available row.
    By vizzy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-06-2013, 10:38 AM
  2. Reference cell from another worksheet if Column and Row headings Match
    By s_parker in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-26-2013, 04:46 AM
  3. Replies: 2
    Last Post: 01-27-2012, 01:32 PM
  4. INDEX MATCH and change column headings
    By thart21 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-22-2011, 11:19 AM
  5. Match any value in row array to column headings
    By learnerabc in forum Excel General
    Replies: 12
    Last Post: 11-15-2010, 03:35 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