Calculate totals and past into second workbook

TotallyConfused

Board Regular
Joined
May 4, 2017
Messages
247
Office Version
  1. 365
Platform
  1. Windows
[TABLE="width: 479"]
<tbody>[TR]
[TD]Hello[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 7"]I have a master file (called MASTER) that contains data similar to that shown below. Its location is at C:\TEST\MASTER.XLSM[/TD]
[/TR]
[TR]
[TD="colspan: 7"]There is another file in the same folder as MASTER, but this one is called C:\TEST\DESTINATION.XLSM[/TD]
[/TR]
[TR]
[TD="colspan: 7"]The sheet in MASTER that contains the data, is named DateEntryTotalsDB and the range of data is named DataEntryTotalsDBRn.[/TD]
[/TR]
[TR]
[TD="colspan: 7"]Since a new row of data will be added every day, MASTER automatically creates the range name and saves it in NAME MANAGER.[/TD]
[/TR]
[TR]
[TD="colspan: 4"]Here is a sample of the data in MASTER[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
Code:
[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]E[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD="align: center"]EXCEL_DATE_V[/TD]
[TD="align: center"]DNUM[/TD]
[TD="align: center"]MNUM[/TD]
[TD="align: center"]YNUM[/TD]
[TD="align: center"]OIL[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD="align: center"]43067[/TD]
[TD="align: center"]28[/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]2017[/TD]
[TD="align: right"]$0.00[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[TD="align: center"]43068[/TD]
[TD="align: center"]29[/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]2017[/TD]
[TD="align: right"]$5.00[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]5[/TD]
[TD="align: center"]43069[/TD]
[TD="align: center"]30[/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]2017[/TD]
[TD="align: right"]$91.25[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]6[/TD]
[TD="align: center"]43070[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]12[/TD]
[TD="align: center"]2017[/TD]
[TD="align: right"]$107.00[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]7[/TD]
[TD="align: center"]43071[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]12[/TD]
[TD="align: center"]2017[/TD]
[TD="align: right"]$0.00[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]8[/TD]
[TD="align: center"]43072[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]12[/TD]
[TD="align: center"]2017[/TD]
[TD="align: right"]$0.00[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 7"]In the 'variables' sheet of DESTINATION I have the following criteria that is used to determe what numbers to search for and total.[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
Code:
[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: center"]MNUM[/TD]
[TD="align: center"]YNUM[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]2017[/TD]
[TD]
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 7"]In DESTINATION's spreadsheet, I've tried different combinations of the following formula but all I get are error messages.[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="colspan: 6"]=DSUM("C:\TEST\MASTER.xlsm" DataEntryTotalsDBRn,5,Variables!A1:B2)[/TD]
[/TR]
[TR]
[TD="colspan: 7"]NOTE: The above formula for November 2017, should give me an answer of $96.25. ($5.00+$91.25)[/TD]
[/TR]
[TR]
[TD="colspan: 7"]I have put together the following VBA code in DESTINATION which will open the MASTER file and activate[/TD]
[/TR]
[TR]
[TD="colspan: 3"]the DataEntryTotalsDB sheet.[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 3"]
Code:
Sub GetMonthsTotals()[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 7"]    Dim ws2 As Variant                             'Sheet in source workbook (wb2) used to calculate totals[/TD]
[/TR]
[TR]
[TD="colspan: 7"]    Dim wb2 As Variant                             'Source workbook used to calculate totals[/TD]
[/TR]
[TR]
[TD="colspan: 7"]  ws2 = "DataEntryTotalsDB"                'Sheet in source workbook (wb2) used to calculate totals[/TD]
[/TR]
[TR]
[TD="colspan: 7"]  wb2 = "C:\TEST\MASTER.xlsm"          'Source workbook used to calculate totals[/TD]
[/TR]
[TR]
[TD="colspan: 6"]Workbooks.Open wb2                               'Open source workbook[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 7"]Sheets("DataEntryTotalsDB").Activate             'Source worksheet used to calculate totals[/TD]
[/TR]
[TR]
[TD]With ws2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 7"]     Range("DataEntryTotalsDBRn").Select            'Source range (in ws2) used to calculate totals[/TD]
[/TR]
[TR]
[TD]End With[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 7"]  ActiveWorkbook.Close                           'Close active workbook (wb2) that is open[/TD]
[/TR]
[TR]
[TD]End Sub
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 2"]Here is what I need to do:[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 7"]From within DESTINATION, I need to search the data in MASTER, find the sum of a range of numbers in a given column[/TD]
[/TR]
[TR]
[TD="colspan: 7"]according to what is specified in the criteria, import this SUM and ONLY the sum, back into Sheet1, cell A1, in DESTINATION.[/TD]
[/TR]
[TR]
[TD="colspan: 7"]Question 1. Is there some other command beside DSUM that I should be using? If so, what, and how is it written?[/TD]
[/TR]
[TR]
[TD="colspan: 7"]Question 2. Is it possible to calculate totals without opening the MASTER workbook? If so, how is this done?[/TD]
[/TR]
[TR]
[TD="colspan: 7"]Question 3. When I close the MASTER workbook, will that create a problem with my formula?[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 7"]I haven't worked with Excel and VBA for very long, so any suggestions or help you may offer will be appreciated.[/TD]
[/TR]
[TR]
[TD]Thank you.[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 2"]TotallyConfused[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,224,830
Messages
6,181,229
Members
453,026
Latest member
cknader

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top