You can get the last non-emtpy cell via
XlDirectionDown = 4
last = wb.Range("A:A").End(XlDirectionDown)
range = wb.Range("A1:A"+str(last))
The XlDirectionDown
is an XlDirection enum item (xlDown
), you can also get its value from COM by dispatching via EnsureDispatch:
xlApp = win32com.client.gencache.EnsureDispatch('Excel.Application')
import win32com.client.constants as cc
XlDirectionDown = cc.xlDown
First line builds the type library for Excel for win32com, which makes constants available.