Excel Macro VBA - Subtotal function issue

Neran

New Member
Joined
Nov 9, 2017
Messages
3
Hi everyone,

I have made a macro to add in a table a sub total from a filtered database.

The sub total function being the only solution, because the SUM function is taking into account all the rows, and I only want the ones which are filtered.
To do so, I have write this :

Range("G53").Activate
ActiveCell.FormulaR1C1 = _
"=SOUS.TOTAL(9;'Sales Database'!M:M)"

But I received an error message each time I am trying to launch it.

Could you help me please ?

You will see the entire macro just below ;)

Thanks !







' DATA CHECKING
Sub Checking()


' Ouverture de la boite de dialogue pour sélectionner l'année d'intérêt à mettre à jour:
Dim Sales_Database As Worksheet
Dim year
year = InputBox("Current Year ? (NUMBERS)")


' Ouverture du fichier de la finance :
Workbooks.Open Filename:= _
"C:\Users\Bertrand.Roche\Desktop\Statistics Report (Summary)"
' Retour dans le fichier MSR :
Windows("GRP.xlsm").Activate
' Positionnement sur l'onglet Checking :
Sheets("Checking").Select
' Ajout des Micros (Renting Qty) provenant du fichier de la finance
Range("H53").Select
ActiveCell.FormulaR1C1 = _
"=SUM('[Statistics Report (Summary).xlsx]GROUP'!R8C22:R16C22)"


' Filtrage des colonnes de la Sales Database
' Positionnement sur la Database :
Sheets("Sales Database").Select
' Se positionne sur le titre de la colonne des années :
Range("A20").Select
' Change le filtre des années en fonction du chiffre donné dans la boite de dialogue ("Field"=n°colonne année) :
ActiveSheet.Range("$A$20:$Z$9999").AutoFilter Field:=1, Criteria1:=year
' Se positionne sur le titre de la colonne des années :
Range("Y20").Select
' Change le filtre de la colonne Product Range :
ActiveSheet.Range("$A$20:$Z$9999").AutoFilter Field:=25, Criteria1:="Micros"


' Positionnement sur l'onglet Checking :
Sheets("Checking").Select
' Ajout des Micros (Renting Qty) provenant du MSR
Range("G53").Activate
ActiveCell.FormulaR1C1 = _
"=SOUS.TOTAL(9;'Sales Database'!M:M)"


'Fermeture du fichier de la finance
Workbooks("Statistics Report (Summary)").Close False


'Confirmation verification des données
If MsgBox("Checking complete !", vbInformation, "Checking") Then


End If
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
It would be
Range("G53").Activate<--remove this line
Range("G53").Value = "=subtotal(9,Sales Database!M:M)"

And the last of if statement makes no sense because there is no returns.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

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