Excel COM - How to use CountA method in AHK
Posted: 18 Jan 2020, 00:03
Hi Folks,
I'm trying to convert the following Excel VBA to AHK:
That code works fine in Excel VBA, with n getting the number of non-blank cells in the column, beginning with the active cell and going down from there for the rest of the column until the last non-blank cell in any column (not just the active column), and selecting those cells in the active column.
I converted the first three VBA lines to AHK as follows:
A MsgBox shows that lastRow and col are correct. Also, the range of cells is properly selected in Excel. However, I'm stuck on the last VBA line, as it's not clear to me what Selection needs to be in AHK for the CountA method. I thought that it would be the value that I assigned to it in the last line posted above, but that doesn't work — n always come back as 1 with this code:
Thanks for your help. Regards, Joe
I'm trying to convert the following Excel VBA to AHK:
Code: Select all
lastRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
col = ActiveCell.Column
Range(ActiveCell, Cells(lastRow, col)).Select
n = Application.CountA(Selection) 'Non-Blank cells in the selection
I converted the first three VBA lines to AHK as follows:
Code: Select all
xlCellTypeLastCell:=11 ; enumeration - https://docs.microsoft.com/en-us/office/vba/api/excel.xlcelltype
xl:=ComObjActive("Excel.Application")
lastRow:=xl.ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
col:=xl.ActiveCell.Column
ActiveCellAddress:=xl.ActiveCell.Address[0,0]
ActiveRange:=xl.Cells(lastRow,col)
Selection:=xl.Range(ActiveCellAddress,ActiveRange).Select
Code: Select all
n:=Floor(xl.CountA(Selection))