-1

Following code gives subtotal of 8th and 9th columns...

My question is why we are using Int32?

What does Int32 mean?

 .Range("A1").CurrentRegion.Subtotal(GroupBy:=7, Function:=Excel.XlConsolidationFunction.xlSum, TotalList:=New Int32() {8, 9}, Replace:=False, PageBreaks:=False, SummaryBelowData:=True)

1 Answers1

1
New Int32() {8, 9}

creates an array of Int32 with the elements 8 and 9.

Using TotalList:=New Int32() {8, 9} passes that as a named parameter to the SubTotal method.

You would have to inspect the SubTotal documentation to determine if an array of Int32 is required if you want to find out if you could use something else.

If the code seems to work without the Int32() then you probably are not using Option Strict On. Almost always, you should use that option to avoid unexpected type conversions which may make your code behave in unintended ways.

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
  • @MichaelScofield - Turning Option Strict On will save you a ton of headaches later on. – Chris Dunaway Feb 23 '16 at 18:55
  • You don't *have* to use Option Strict On, but by using it you get the help of the compiler to go a long way towards ensuring your code will work predictably. [The many memes of Meta](http://meta.stackexchange.com/a/273139/232762). Option Explicit *is* optional. Option Strict was left off by default so that people migrating from VB6 (yes, all those years ago) would not see so many problems with their code - many people consider this choice was a mistake. – Andrew Morton Feb 23 '16 at 18:58
  • Use your mouse - Visual Studio will offer solutions to each. Accept the one it offers. Its *that* hard. @MichaelScofield – Ňɏssa Pøngjǣrdenlarp Feb 23 '16 at 19:07
  • @MichaelScofield you need to do some research on your own. That WMI stuff will have to be rewrttien to do it right – Ňɏssa Pøngjǣrdenlarp Feb 23 '16 at 19:36