Calculate totals and past into second workbook

TotallyConfused

Board Regular
Joined
May 4, 2017
Messages
247
Office Version
  1. 365
Platform
  1. Windows
Hello
I have a master file (called MASTER) that contains data similar to that shown below. Its location is at C:\TEST\MASTER.XLSM
There is another file in the same folder as MASTER, but this one is called C:\TEST\DESTINATION.XLSM
The sheet in MASTER that contains the data, is named DateEntryTotalsDB and the range of data is named DataEntryTotalsDBRn.
Since a new row of data will be added every day, MASTER automatically creates the range name and saves it in NAME MANAGER.
Here is a sample of the data in MASTER
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]
In the 'variables' sheet of DESTINATION I have the following criteria that is used to determe what numbers to search for and total.
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]
In DESTINATION's spreadsheet, I've tried different combinations of the following formula but all I get are error messages.
=DSUM("C:\TEST\MASTER.xlsm" DataEntryTotalsDBRn,5,Variables!A1:B2)
NOTE: The above formula for November 2017, should give me an answer of $96.25. ($5.00+$91.25)
I have put together the following VBA code in DESTINATION which will open the MASTER file and activate
the DataEntryTotalsDB sheet.
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
Here is what I need to do:
From within DESTINATION, I need to search the data in MASTER, find the sum of a range of numbers in a given column
according to what is specified in the criteria, import this SUM and ONLY the sum, back into Sheet1, cell A1, in DESTINATION.
Question 1. Is there some other command beside DSUM that I should be using? If so, what, and how is it written?
Question 2. Is it possible to calculate totals without opening the MASTER workbook? If so, how is this done?
Question 3. When I close the MASTER workbook, will that create a problem with my formula?
I haven't worked with Excel and VBA for very long, so any suggestions or help you may offer will be appreciated.
Thank you.
TotallyConfused

<tbody>
</tbody>
 
Last edited:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

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