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:14:02
 
 
To
11/03/2004 15:00:58
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00885317
Message ID:
00885351
Views:
36
This message has been marked as a message which has helped to the initial question of the thread.
Tracy, Count is not an object, it's a property. You can't use:
With .......Count
You need
With oExcel
    For ix = 1 to .ActiveWorkbook.ActiveSheet.UsedRange.Rows.Count
....
EndFor
Alan


>Yuri,
>I tried .ActiveSheet.usedRange.Rows.count and I get datatype mismatch... I cannot locate the property in the debugger to determine what's wrong with it:
>
>
>
>WITH oExcel
>  .Workbooks.OPEN(lcXLSFile)
>
>   *ORIGINAL LINE:
>   *WITH .ActiveWorkbook.ActiveSheet.RANGE(lcRange) && works but I have to guess the range
>
>   *NEW LINE:
>   WITH .ActiveWorkbook.ActiveSheet.UsedRange.Rows.Count && <-error datatype mismatch
>
>
>
>
>>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
Reply
Map
View

Click here to load this message in the networking platform