+ Reply to Thread
Results 1 to 7 of 7

returning a variant

  1. #1
    Registered User
    Join Date
    02-07-2010
    Location
    Manchesteer
    MS-Off Ver
    Excel 2007
    Posts
    51

    returning a variant

    I'm sure this is simple but i acn't work it out. I have a variant called 'lastweek' taht i want to return its value to an excel cell. The code should loop through cells B31-99 (these are dates). if any with the last 7 days then it adds the value of the equivilant cell 3 columns accross to 'lastweek'. - this isn't working tho - any idea's?

    Please Login or Register  to view this content.
    Thanks,
    Mark
    Last edited by mark-ainsworth; 04-18-2011 at 12:04 PM.

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: returning a variant

    This is just a guess, if it is not what you mean then post a sample workbook showing your data in Columns B & E and the expected result in N7
    Please Login or Register  to view this content.
    Last edited by Marcol; 04-17-2011 at 11:01 AM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  3. #3
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: returning a variant

    Please Login or Register  to view this content.
    Hell Marcol:
    I could be wrong , but I think the OP wants to loop thru all cells in date range and sum the value

    VBA SOLUTION
    Please Login or Register  to view this content.
    .
    .
    .

    FORMULA SOLUTION

    =SUMIF(B31:B99,"<=" & TODAY() -7,E31:E99)
    Last edited by nimrod; 04-17-2011 at 02:03 PM.

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: returning a variant

    @ nimrod I saw that, but couldn't see why that would be required, there could be all sorts of dates >= to Date()-7, in any order. That will just return the last one found.

  5. #5
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: returning a variant

    lastweek.Value = lastweek.Value + c.Offset(0, 3).Value
    Hi Marcol

    To me this line indicates the OP is basically wanting to do a "SumIf" based on a date range i.e. take a numbers from offset 0,3 and tally them up ... oh well , the OP can decide what he/she wants from the posts ... cheers

  6. #6
    Registered User
    Join Date
    02-07-2010
    Location
    Manchesteer
    MS-Off Ver
    Excel 2007
    Posts
    51

    Re: returning a variant

    Thinkk I'm more confused now. Sorry.

    This is my current code:

    Please Login or Register  to view this content.
    The above works fine. What i want to add in is when the 'For' loop is looping round the worksheets, i want it to do a second loop through the cells B31:B99 and look if any of the dates in this loop are in the last 7 days. If there are I want it to add the corresponding value in coulmn E to the total 'lastweek'. After moving through each of the worksheets. the total will then be written to cell N7.

    FYI Column B contains dates and column E contains payments in £.

    Thanks,
    Mark

  7. #7
    Registered User
    Join Date
    02-07-2010
    Location
    Manchesteer
    MS-Off Ver
    Excel 2007
    Posts
    51

    Re: returning a variant

    Worked it out - sorry

+ 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