Consulting

Results 1 to 4 of 4

Thread: Sum Values in defined target

  1. #1

    Sum Values in defined target

    I have a workbook that essentially looks through a bunch of data sheets, to ultimately return a given value within a given date range.

    Within a userform the user will enter a "from date" and a "to date" along with some other criteria, and I have a hidden text box in the form, which determines the number of days "days.text".

    I am able to determine the target cell of the "criteria" and "To Date". Let's say the target is (20, 8). The value of "days.text" is 5 based on the "From date". So I'll need to sum (15, 8) + (16, 8) + (17, 8) + (18, 8) + (19, 8) + (20, 8).

    Here is the order of things:
    Listbox - Select Sheet
    DatePicker - From Date
    DatePicker2 - To Date
    Listbox2 - Criteria
    days.text - Shows number of days we'll say it's "5"

    I'm able to find the "Sheet" and target of "DatePicker2 (Row)" and "Criteria (Column)"

    How can I tell VB to: with target offset by days.text "5", Sum to target..

  2. #2
    VBAX Mentor
    Joined
    Jun 2004
    Posts
    363
    Location
    Something like this:
    [VBA]Application.WorksheetFunction.Sum(Cells(20, 1).Offset(-5).Resize(6, 1))[/VBA]

  3. #3
    Works perfect, thanks!!
    Result [VBA]Dbtarget = Application.WorksheetFunction.Sum(target.Offset(-nod.value).Resize(nod.value + 1))[/VBA]

  4. #4
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    You can shorten:
    [VBA]
    Dbtarget = Application.WorksheetFunction.Sum(target.Offset(-nod.value).Resize(nod.value + 1))
    [/VBA]

    To:
    [VBA]
    Dbtarget = Application.Sum(target.Offset(-nod.value).Resize(nod.value + 1))
    [/VBA]
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

Posting Permissions

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