Jump to content

[SOLVED] How to perform a Subtotal in Excel using Autoit


Recommended Posts

@junkew Here is what I tried. This line of code is full of errors though. (Syntax and statement cannot be just an expression)

Worksheets(1).Cells.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(7), Replace:=True, PageBreaks:=False, SummaryBelowData:=True

I used VBA to record this like you said and showed me. I just do not know how to properly transform this into the Autoit language.

Any hints or tips?

Link to comment
Share on other sites

AutoIt does not support named parameters.
MSDN explains how positional parameters need to be specified: https://docs.microsoft.com/de-de/office/vba/api/excel.range.subtotal

Untested:

Global $aTotalList[1] = [7]
$oWorkbook.Worksheets(1).Cells.Subtotal(2, $xlSum, $aTotalList, True, False, True)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

@water

Here is what I have/had as of 1 and a half hours ago.

Const $xlSum = -4157
Global $sub_Array[7] = [1, 2, 3, 4, 5, 6, 7]
$oRange = $OpenWorkbook.Activesheet.Range("A1:N" & $IndexRows)
$oRange.Subtotal(2, $xlSum, $sub_Array, True, False, True)

I do not understand what the

$xlSum = -4157

means I just know it is needed.

This pretty much works but I have to collapse it manually once the subtotal runs. The only issue I am having is that I need it to "add the subtotal to" Row 1 Col 6 and I think it's adding it to Row 1 Col 5.

any tips would be great. 

Link to comment
Share on other sites

xlsum defines that the subtotal shoudl sum up the values. You could calculate average, product ... as described here: https://docs.microsoft.com/en-us/office/vba/api/excel.xlconsolidationfunction

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

@water Thank you very much. I got the code to work perfectly now the only thing I need is to transform this VBA code into Autoit code so it can collapse the subtotal for me. 

 

 ActiveSheet.Outline.ShowLevels RowLevels:=2

Where do I go to find out how to properly edit this so it will work in Autoit? 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...