Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Excel automation - determine last populated row in sheet
Message
 
To
11/03/2004 14:15:12
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00885317
Message ID:
00885320
Views:
35
I believe, you need USedRange:
ObjExcel.ActiveSheet.UsedRange.Rows.Count

This also may help:
*xlLastCell=11
ObjExcel.ActiveSheet.Range("A1").SpecialCells(xlLastCell).Address(.f.,.f.,-4150)

>I have code that steps through the rows of a spreadsheet and populates a table with the values from some of the columns. However, it requires that I specify the range to work with when I open the worksheet. Is there anyway to determine the last row in the spreadsheet that is populated (not blank) without stepping through all of the rows? I know what column to check: 5. The values I am grabbing are in column five of the spreadsheet and there may be an error which would leave a blank row in the middle of the spreadsheet. The spreadsheet might actually have data in it until row 900 for instance...
>
>TIA,
>Tracy
>
>
>LOCAL lcXLSFile, lcRange, llfound, lncount, oExcel, lcvalue, lnlength, lcdir
>lcRange = "a1:E1000" && just guessing range here!
>llfound = .F.
>lncount = 0
>lcvalue = ''
>lnlength = 0
>lcdir = ''
>
>*--More stuff
>
>*--Loop through all xls files in the directory
>FOR ifile = 1 TO ALEN(lafiles,1)
>	m.fieldname = ''
>	m.corder = ''
>	m.cver = ''
>	m.cform = ''
>	IF TYPE('lafiles(ifile,1)')="C" .AND. !EMPTY(lafiles(ifile,1))
>		lcXLSFile=lcdir+lafiles(ifile,1)
>	ELSE
>		LOOP
>	ENDIF
>	oExcel = CREATEOBJECT("excel.application")
>	WITH oExcel
>		.Workbooks.OPEN(lcXLSFile)
>		WITH .ActiveWorkbook.ActiveSheet.RANGE(lcRange)
>			FOR ix = 1 TO .ROWS.COUNT
>
>*--Here is where I check to see if the ix,5 is empty or not.  If I pass
>*--three empty rows in sequence then I exit the loop because I am probably
>*--at the end of the spreadsheet.
>*--I would like to specify the correct range above in the line:
>*--WITH .ActiveWorkbook.ActiveSheet.RANGE(lcRange) <== ? correct range
>
>*--More Stuff
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform