I can read any cell I specify, but can you read to the end of the excell file??
Is that possible??
Printable View
I can read any cell I specify, but can you read to the end of the excell file??
Is that possible??
Welcome to the Forums.
Yes, but what exactly are you needing to do? You can do this several ways.
There is the .UsedRange function or the .SpecialCells function. Which to use will depend on your needs but both will work.
Here's the deal... :)
I have two spreadsheets I'm reading in two different workbooks.
I'm having to read each sheet, and then put them each into the same dataSet. But each goes into its own dataTable. Then I need to compare them once I've done that.
I can do this if I know exactly how many rows are in each spreadsheet, but the problem is these are going to change, maybe daily. So I need to be able to read to EFO of the spreadsheets, then where there is no more data, stop.
Can I use UsedRange or .SpecialCells for this? Or is there any other function or way?
Here's a step-by-step instruction from MS that shows 2 methods for finding the end of existing data:
http://www.microsoft.com/technet/scr.../tips0421.mspx
I think this will help you with what you are trying to do.
EDIT:
This instruction is actually for appending data to an existing data range, but it still shows you how to find the end of your existing data.
If you can guarantee that one of the columns will have data in every cell you can use
orCode:set rng = sht.cells(1,1).End(xlDown)
Then you can get the row withCode:set rng = sht.cells(65535,1).End(xlUp)
Another option...Code:debug.print rng.row
rng is a range object
sht is a worksheet
Cells is an Excel method.
xlUp/Down are variables declared in Excel.
This mimics the button presses : End, then Down/Up from cell A1/A65535 (depending if you are going up or down).