Changing a Sumifs to a Sumproduct

Joshua Kao

New Member
Joined
Feb 14, 2021
Messages
16
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi, could someone please help me convert the sumifs formula in VBA, to a sumproducts please? Thank you.

ActiveCell.FormulaR1C1 = _
"=SUMIFS('Closing Stock.xlsx'!C3,'Closing Stock.xlsx'!C1,RC[-4])"
 
Is there a header in that column?
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
In that case try
VBA Code:
 ActiveCell.FormulaR1C1 = _
        "=SUMPRODUCT(('C:\Users\Joshua Kao\Desktop\PHMG\Stock Take\PS\[Closing Stock.xlsx]closing stock-PS'!R2C3:R1000C3)*('C:\Users\Joshua Kao\Desktop\PHMG\Stock Take\PS\[Closing Stock.xlsx]closing stock-PS'!R2C1:R1000C1=rc[-4]))"
Change the R1000 to a number that is large enough to cover your entire data, without going to large.
 
Upvote 0
Solution
it works now. Thank you so much!. If you don't mind, i have another question. If i want to copy paste from a closed workbook to the current workbook, what command should i use for it? I have it working when the data workbook is opened, but not when its closed. ive posted my current code below.

VBA Code:
    Windows("PHMG Medicine Master.xlsx").Activate
    Range("A2:D2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Application.CutCopyMode = False
    Selection.Copy
    Windows("Consolidated Workbook.xlsm").Activate
    Sheets("ComparisonM2K").Select
    Range("A2").Select
    ActiveSheet.Paste
 
Upvote 0
As that's a totally different question you will need to start a new thread.
With regard to this thread you can get rid of the loop like
VBA Code:
   irow = Cells(Rows.Count, 1).End(xlUp).Row
   Range("E2:E" & irow).FormulaR1C1 = _
        "=SUMPRODUCT(('C:\Users\Joshua Kao\Desktop\PHMG\Stock Take\PS\[Closing Stock.xlsx]closing stock-PS'!R2C3:R1000C3)*('C:\Users\Joshua Kao\Desktop\PHMG\Stock Take\PS\[Closing Stock.xlsx]closing stock-PS'!R2c1:R1000C1=rc[-4]))"
    Range("F2:F" & irow).FormulaR1C1 = _
        "=SUMIFS(Master!C[-3],Master!C[-5],ComparisonM2K!RC[-5],Master!C[-2],ComparisonM2K!RC[-3])"
    Range("G2:G" & irow).FormulaR1C1 = "=(RC[-2]/RC[-1])*100-100"
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
sorry, i have another question regarding the code, would it be possible to do something like this
VBA Code:
 fnameList = Application.GetOpenFilename(FileFilter:="Microsoft Excel Workbooks (*.xls;*.xlsx;*.xlsm),*.xls;*.xlsx;*.xlsm", Title:="Choose Excel files to merge", MultiSelect:=True)
to select the closing stock workbook instead of it pointing directly to a specific directory? This is because it will not always be my computer that it is on
 
Upvote 0
Will it always be in the same location, just a different user name?
 
Upvote 0
yep, it will always be on C:/users/"username"/desktop/"foldername"/. Its will either be here, or be in the downloads folder.
 
Upvote 0

Forum statistics

Threads
1,223,936
Messages
6,175,507
Members
452,650
Latest member
Tinfish

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