Jump to content

is this possible - excel insert totals


Go to solution Solved by JLogan3o13,

Recommended Posts

Posted

I have an excel file that contains an account number and a dollar amount. Each day the file will have a different number of rows. Is it possible to have AutoIt open the excel file, determine the last row, and insert a count on the account number field and a sum on the dollar amount field?

  • Moderators
Posted

It is possible. If you want to write on the last row with data in it, you could do this:

Const $xlCellTypeLastCell = 11

$oExcel = ObjCreate("Excel.Application")
    $oBook = $oExcel.Workbooks.Open("C:\Users\JeremiaL\Desktop\Test.xls")
    $oExcel.Visible = True
    $oSheet = $oBook.Worksheets(1)
    $oSheet.Activate

    $oRange = $oSheet.UsedRange
    $oRange.SpecialCells($xlCellTypeLastCell).Activate

If you want the first open row, add this to the end:

$newRow = $oExcel.ActiveCell.Row + 1
    $oExcel.Range("A" & $newRow).Activate

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

 

It is possible. If you want to write on the last row with data in it, you could do this:

Const $xlCellTypeLastCell = 11

$oExcel = ObjCreate("Excel.Application")
    $oBook = $oExcel.Workbooks.Open("C:\Users\JeremiaL\Desktop\Test.xls")
    $oExcel.Visible = True
    $oSheet = $oBook.Worksheets(1)
    $oSheet.Activate

    $oRange = $oSheet.UsedRange
    $oRange.SpecialCells($xlCellTypeLastCell).Activate

If you want the first open row, add this to the end:

$newRow = $oExcel.ActiveCell.Row + 1
    $oExcel.Range("A" & $newRow).Activate

 

Thanks, that gets me part of the way there. Any idea how to get it to insert a 'sum' and a 'count'?

  • Moderators
Posted

So you want a sum of all dollar amounts? How about a screenshot of an excel example, so we can see how you have/want the data laid out? Then it should be relatively easy to get you where you want to be.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted (edited)

So you want a sum of all dollar amounts? How about a screenshot of an excel example, so we can see how you have/want the data laid out? Then it should be relatively easy to get you where you want to be.

 

screenshot attached...

post-13077-0-14370400-1394487931_thumb.j

Edited by erik7426
  • Moderators
  • Solution
Posted

Ok, I'm not sure what the purpose of the count numbers are, or how you're totaling them, but for a subtotal you could do something like this:

 

Beginning with this:

post-54985-0-09157800-1394494503_thumb.p

 

You could do something like this:

#include <Excel.au3>
 
Local $subTotal, $grandTotal
$oExcel = _ExcelBookOpen(@DesktopDir & "\Test.xls")
$oRange = $oExcel.Worksheets(1).UsedRange
$oRange.SpecialCells($xlCellTypeLastCell).Activate
$oRow = $oExcel.ActiveCell.Row
$subTotalArray = _ExcelReadArray($oExcel, 2, 3, $oRow, 1)
 
For $element in $subTotalArray
   $subTotal += $element
Next
 
$grandTotal = _ExcelWriteCell($oExcel, $subTotal, $oRow + 1, 3)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...