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 14:15:12
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Excel automation - determine last populated row in sheet
Miscellaneous
Thread ID:
00885317
Message ID:
00885317
Views:
104
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
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Next
Reply
Map
View

Click here to load this message in the networking platform