Jump to content

Help Excel Range Read


Go to solution Solved by ioa747,

Recommended Posts

Posted

Counting non-blank cell returns 16

$oExcel = ObjCreate("Excel.Application")

Local $sWorkbook = "Z:\Test.xlsx"

$oWorkbook = _Excel_BookAttach($sWorkbook)

$oWorkbook.Worksheets("EXAMPLE").Activate
$oRange = $oWorkbook.Activesheet.Range("D15:D30")
MsgBox(4096, "Excel Count Non-Blank Cells", $oExcel.WorksheetFunction.CountA($oRange))

 

Counting non-blank cell returns 4

#include <Excel.au3>
$oExcel = ObjCreate("Excel.Application")

Local $oWorkbook = _Excel_BookOpen($oExcel, "Z:\Test.xlsx")

$oRange = $oExcel.ActiveSheet.Range("D15:D30")
MsgBox(4096, "Excel Count Non-Blank Cells", $oExcel.WorksheetFunction.CountA($oRange))

what's wrong with the first code?

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

  • 232showtime changed the title to Help Excel Range Read
  • Solution
Posted (edited)

https://www.autoitscript.com/wiki/Excel_Range

 

#include <Excel.au3>
$oExcel = ObjCreate("Excel.Application")

;~ Local $sWorkbook = "Z:\Test.xlsx"
Local $sWorkbook = @ScriptDir & "\Test.xlsx"

Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook)
;~ Local $oRange = $oWorkbook.Sheets(1).Range("D15:D30")
Local $oRange = $oWorkbook.Worksheets("EXAMPLE").Range("D15:D30")

; 0 + if no value
$NonBlankCount = 0 + $oExcel.WorksheetFunction.CountIf($oRange, "<>")

MsgBox(4096, "Excel Count Non-Blank Cells", $NonBlankCount)

; Clean up
$oWorkbook.Close(False) ; Close the workbook without saving
$oExcel.Quit() ; Quit Excel

 

Edited by ioa747
added ; Clean up

I know that I know nothing

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...