Results 1 to 5 of 5

Thread: Can you read to EOF in excel??

  1. #1

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    60

    Can you read to EOF in excel??

    I can read any cell I specify, but can you read to the end of the excell file??
    Is that possible??

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Can you read to EOF in excel??

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    60

    Re: Can you read to EOF in excel??

    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?

  4. #4
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    Re: Can you read to EOF in excel??

    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.
    Last edited by New2vba; May 8th, 2006 at 01:08 PM.
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

  5. #5
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Can you read to EOF in excel??

    If you can guarantee that one of the columns will have data in every cell you can use
    Code:
        set rng = sht.cells(1,1).End(xlDown)
    or
    Code:
        set rng = sht.cells(65535,1).End(xlUp)
    Then you can get the row with
    Code:
        debug.print rng.row
    Another option...
    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).

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width