+ Reply to Thread
Results 1 to 9 of 9

Sum if named range begins with

  1. #1
    Registered User
    Join Date
    12-17-2019
    Location
    Leeds, UK
    MS-Off Ver
    365
    Posts
    61

    Unhappy Sum if named range begins with

    Hi,

    I have traffic junctions flow data in 2 sheets: AM_Flows and PM_Flows.
    Both sheets contain the traffic flow through each arm of each junction.
    I have used named ranges to reference the time period (AM or PM), the highway junction code (eg. J3, J29, J35A etc.) and the junction arm (A,B,C or D).
    So for example, named cell reference AM_J30_A contains the morning flows from Junction 30 arm A.
    AM_J30_A + AM_J30_B + AM_J30_C + AM_J30_D = the total morning flow through Junction 30.

    In a separate sheet, I have a table that needs to calculate the total flows through each junction (i.e. the sum of flows through every arm of a given junction) for each time period.

    The formula would need to be dynamic in 2 ways:
    - the table's column headers are AM and PM, so the column of a given cell in the table determines which set of named ranges are SUMed (e.g. AM_J30_A vs. PM_J30_A)
    - The table's row headers are the junction codes, so the row of a given cell in the table again determines which set of named ranges are SUMed (e.g. AM_J30_A or AM_J31_A etc).

    It seems that I can't use a SUMIF(INDIRECT(Period_Junction_*) i.e. sum any named range which starts with the desired time period and junction code.

    Any help would be greatly appreciated. See attached.
    Attached Files Attached Files
    Last edited by aurelien_21; 05-01-2023 at 07:11 AM.

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,205

    Re: Sum if named range begins with

    Please add expected results for a couple of junctions.

    and VBA as a possible solution?
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Registered User
    Join Date
    12-17-2019
    Location
    Leeds, UK
    MS-Off Ver
    365
    Posts
    61

    Re: Sum if named range begins with

    Hi John, I've updated the Excel attachment.
    It will be my intention to automate this with VBA at some point. If a VBA script does seem like the best solution and you are able to still help, that would be greatly appreciated too!

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,205

    Re: Sum if named range begins with

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by JohnTopley; 05-01-2023 at 10:37 AM.

  5. #5
    Registered User
    Join Date
    12-17-2019
    Location
    Leeds, UK
    MS-Off Ver
    365
    Posts
    61

    Re: Sum if named range begins with

    That's fantastic, thanks very much John. Out of interest, I've never worked with Dim a,b. Can you describe what this is about and how you've use it? Thanks again

  6. #6
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,205

    Re: Sum if named range begins with

    See here (as a start)

    https://excelchamps.com/vba/dim/

    "Dim a,b" will default to atribute of variant: you other variables have their attributes defined (Integer, Long etc)

    This ..

    Please Login or Register  to view this content.
    assigns the range B3:E (to last row) into "a" (which an array): array processing is much faster than read/write to cells

    Looking at the code "b" is redundant obviously changed my thinking when developing the code)!

    Out of interest, I renamed (some of )the junctions by adding a prefix of "J" (J7AB, J34CD ...) and added code which did the calculation by referencing the junctions rather than using named ranges.

  7. #7
    Registered User
    Join Date
    12-17-2019
    Location
    Leeds, UK
    MS-Off Ver
    365
    Posts
    61

    Re: Sum if named range begins with

    Thanks John, That's very interesting actually because I've realised I don't want to include any mainline flows (i.e AB and BA movements that don't actually *use* the interchange). Sounds like referencing the junction codes (J7AB, J34CD ...) would create that possibility because the code could simply omit AB and BC from those sums?

  8. #8
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,205

    Re: Sum if named range begins with

    I think this is possible: I currently do a "wildcard" search for a junction e.g. J34" but this will still allow for the omission of certain junction codes.

  9. #9
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,205

    Re: Sum if named range begins with

    See attached example: "Sheet "Output" with input from "AM Flows test". 2 Junctions 7 & 35

    Please Login or Register  to view this content.
    Last edited by JohnTopley; 05-06-2023 at 04:13 AM.

+ 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. Listbox displaying named range B but Adding named range A to cell
    By ikkenieikke in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-05-2018, 02:27 PM
  2. [SOLVED] Compare cells to named range and create new sheets using related named range
    By drewship in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-10-2015, 03:35 PM
  3. [SOLVED] Assign named range to one cell depending on named range in another
    By x65140 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-22-2015, 11:04 AM
  4. Replies: 4
    Last Post: 02-20-2015, 09:40 AM
  5. Resultant cell to be blank, not zero, until range begins population
    By craigl in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-07-2015, 03:27 PM
  6. Adding row to a named range-updating the named range address
    By kjsconv in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-12-2013, 11:22 PM
  7. [SOLVED] Determine what Named Range the Target Address is and return Named Range Name
    By jordan2322 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-18-2012, 10:49 PM

Tags for this Thread

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