+ Reply to Thread
Results 1 to 14 of 14

Sum Data From a Dynamic Range of A Column On Another Worksheet

  1. #1
    Registered User
    Join Date
    10-12-2024
    Location
    This is a site run by a bunch of fascists!
    MS-Off Ver
    Fascist Site!
    Posts
    16

    Sum Data From a Dynamic Range of A Column On Another Worksheet

    Hello,

    I have a workbook with multiple worksheets, and on one of them (the "Summary" worksheet) I'm trying to sum all the data within a dynamic range of a column on another spreadsheet. I know I can use Excel's SUM formula, but I would like to automate this with a macro that will automatically run the summation for me as i have multiple different sum values I'm trying to organize and analyze.

    I've attached a sample workbook and some screen shots here to illustrate what I'm trying to achieve.

    Screenshot 003239.png
    Screenshot 003357.png
    Attached Files Attached Files

  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
    29,968

    Re: Sum Data From a Dynamic Range of A Column On Another Worksheet

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


    Renamed data sheets as Data1, Data2 purely for illustration so just change to first/last sheet names (must be consecutive)

    And ensure descriptions in column A match your headers
    Attached Files Attached Files
    Last edited by JohnTopley; 10-14-2024 at 06:03 AM.
    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-30-2020
    Location
    Here
    MS-Off Ver
    M365
    Posts
    63

    Re: Sum Data From a Dynamic Range of A Column On Another Worksheet

    IF you use same title name, OFFSET or INDIRECT function could help.
    (I modified title text in SourceData for matching)
    SUBSTITUTE function is used for matching titles, and if B3 cell has Source_Sheet_Name,
    try this formula.
    B4 =SUM(OFFSET(INDIRECT("'"&$B$3&"'!$A$1"),0, MATCH(SUBSTITUTE(SUBSTITUTE($A4,"Total ",""),":",""),INDIRECT("'"&$B$3&"'!$A$1:$Z$1"),0)-1, COUNTA(INDIRECT("'"&$B$3&"'!$A:$A"))) )

    If you must need VBA code, please let me know.

    스크린샷 2024-10-14 172155.png
    Attached Files Attached Files
    Last edited by mojirhi; 10-14-2024 at 04:23 AM.

  4. #4
    Registered User
    Join Date
    10-12-2024
    Location
    This is a site run by a bunch of fascists!
    MS-Off Ver
    Fascist Site!
    Posts
    16

    Re: Sum Data From a Dynamic Range of A Column On Another Worksheet

    Thank you for this information. Is there a way to translate this into a VBA code to automate this?

  5. #5
    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
    29,968

    Re: Sum Data From a Dynamic Range of A Column On Another Worksheet

    What "automation" is required ? as the formulae will retrieve the results automatically - no change required other than to make the range your likely maximum.

    One time set-up.
    Last edited by JohnTopley; 10-14-2024 at 12:10 PM.

  6. #6
    Registered User
    Join Date
    10-12-2024
    Location
    This is a site run by a bunch of fascists!
    MS-Off Ver
    Fascist Site!
    Posts
    16

    Re: Sum Data From a Dynamic Range of A Column On Another Worksheet

    The automation is the formula embedded in the VBA code that will perform other automation tasks with a macro as well.

  7. #7
    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
    29,968

    Re: Sum Data From a Dynamic Range of A Column On Another Worksheet

    Attached code simply applies the formula given earlier. There are 2 sheets(First/Last) which are a prefix/suffix to your data sheets

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by JohnTopley; 10-14-2024 at 01:15 PM.

  8. #8
    Registered User
    Join Date
    10-12-2024
    Location
    This is a site run by a bunch of fascists!
    MS-Off Ver
    Fascist Site!
    Posts
    16

    Re: Sum Data From a Dynamic Range of A Column On Another Worksheet

    Thank you for this code, but "$A$1:$T$1000" is not a dynamic range as the range size of the data can vary. How do I make this part dynamic to adjust accordingly to the range size of the data?

  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
    29,968

    Re: Sum Data From a Dynamic Range of A Column On Another Worksheet

    If the data range varies from sheet to sheet then you need to process each sheet individually ( a loop of some kind) or simply make the range the likely maximum if you want a simple formula as provided.

  10. #10
    Registered User
    Join Date
    10-12-2024
    Location
    This is a site run by a bunch of fascists!
    MS-Off Ver
    Fascist Site!
    Posts
    16

    Re: Sum Data From a Dynamic Range of A Column On Another Worksheet

    Yup, exactly why I need a macro to do the job! Thank you for the feedback though.

  11. #11
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,665

    Re: Sum Data From a Dynamic Range of A Column On Another Worksheet

    If you change "Total Expenses" in SourceData sheet to "Expenses" and "Mileage Activity Totals" to "Mileage Activity" so that your consistent with the entries in Summary sheet.
    The text in Column A in Summary Sheet should match the text you're comparing in Row1 in SourceData Sheet with Total and a space ("Total ")in front of it and the ":" following it.
    Please Login or Register  to view this content.
    The inherent weakness of the liberal society: a too rosy view of humanity.

  12. #12
    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
    29,968

    Re: Sum Data From a Dynamic Range of A Column On Another Worksheet

    Building on Jolivanes' code: assumes all sheets EXCEPT "Summary" are to be processed ..

    Please Login or Register  to view this content.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    10-12-2024
    Location
    This is a site run by a bunch of fascists!
    MS-Off Ver
    Fascist Site!
    Posts
    16

    Re: Sum Data From a Dynamic Range of A Column On Another Worksheet

    Thank you Jolivanes and JohnTopley for these codes! I do want to understand a bit better on the rationale behind these codes, so may I ask the following:

    1) What is "ReDim" and its purposes here in this code?
    2) I see the first FOR loop ("For i = 1 To WS_Count") and I'm assuming this loop is to loop through all the worksheets within the workbook, correct?
    3) Why is "n = 0" within the first FOR loop?
    4) Why is "n = n+1" in the second FOR loop?
    5) I have a basic understanding of Resize, which is used to change the size of a range, but what is its purpose here?

  14. #14
    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
    29,968

    Re: Sum Data From a Dynamic Range of A Column On Another Worksheet

    Commented the code ...


    Please Login or Register  to view this content.

+ 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. VBA - Copy and paste dynamic range column from one worksheet to another
    By ChrisFoster1uk in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-11-2020, 09:22 AM
  2. Replies: 2
    Last Post: 05-22-2020, 03:30 AM
  3. Selecting a dynamic range of data based off column data
    By wizeone in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-28-2014, 10:44 PM
  4. [SOLVED] Dynamic range from every nth value in a column in a data validation list
    By Xaoc in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-08-2013, 08:47 AM
  5. Dynamic range with changing worksheet as data source
    By JuJuBe in forum Excel General
    Replies: 0
    Last Post: 11-15-2011, 05:15 PM
  6. Replies: 0
    Last Post: 09-15-2011, 08:24 PM
  7. Dynamic column chart - auto sort on data range
    By jimfrog in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 03-29-2006, 09:50 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