How to determine the end of the document

R

raz230

I am learning some excel programming for use in a ASP web site. I need
to select a range of cells and then process what I select. I am
getting along OK with that part, but how can I determine what to select
so that I avoid selecting rows that don't have any data?

EG, I have columns "A" through "O" to work with. There is some header,
title and report title text and basically some non-related things at
the top of the worksheet. Data starts at [A9]

If I knew that the report always ended at line 500, I could select
[A9:O500]- but the report varies in length.

here is a code sample of what I am doing: Any advice would be much
appreciated.

I am constrained by circumstances to use ASP.


Dim ExcelConn
Set ExcelConn = Server.CreateObject("ADODB.Connection")
With ExcelConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Extended Properties").Value = "Excel 8.0"
.Open Server.mappath("/Reports/Processing/ImportedInvoices/test.xls")
.Properties("Jet OLEDB:Max Buffer Size") = 256
End With


Dim objRs
Set objRs = Server.CreateObject("ADODB.Recordset")
With objRs
Set .ActiveConnection = ExcelConn
.Open "Select * from [Sheet1$A9:O500]" 'how do I know what to
select???
End With


Do While NOT objRs.EOF

Response.Write objRs.Fields.Item(0) & " " & objRs.Fields.Item(1) &
"<br>"
objRs.MoveNext

Loop

objRs.Close
Set objRs = Nothing

ExcelConn.Close
Set ExcelConn = Nothing
 
J

John Bundy

I haven't had to use ASP to work with Excel yet but this is the code to give
you the last row number in a particular column that is not blank.

lastCell = Cells(Rows.Count, "A").End(xlUp).Row
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top