Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Excel automation - determine last populated row in sheet
Message
From
11/03/2004 15:21:27
 
 
To
11/03/2004 14:15:12
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00885317
Message ID:
00885356
Views:
21
This message has been marked as a message which has helped to the initial question of the thread.
Hi Tracy,

Here is some code from an Excel Converter I created. Seems to work for me.
	*!* Select all data in worksheet
	This.oXL.Range('A1').Select
	This.oXL.Range(This.oXL.Selection,This.oXL.ActiveCell.SpecialCells(11)).Select

	*!* Store number of rows containing data
	This.nRows = This.oXL.Selection.Rows.Count 
	*!* Store number of columns containing data
	This.nColumns = This.oXL.Selection.Columns.Count
>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
Reply
Map
View

Click here to load this message in the networking platform