+ Reply to Thread
Results 1 to 2 of 2

Finding the last nonblank cell in a column in VBA or VSTO

  1. #1
    Bob Sullentrup
    Guest

    Finding the last nonblank cell in a column in VBA or VSTO

    Folks,

    In VBA I have frequently used the formula:

    last_row = ActiveWorkbook.Sheets("Sheet1").Range("A65534").End(xlUp).Row

    to find the last cell with data in it in column A of Sheet1.

    In Visual Studio Tools for Office (C#) the equivalent expression I have just
    discovered is:

    Sheet1.get_Range("A65534", Type.Missing).get_End(Excel.XlDirection.xlUp).Row

    --
    Bob Sullentrup

  2. #2
    William Benson
    Guest

    Re: Finding the last nonblank cell in a column in VBA or VSTO

    Your method would not work if the last cell used was on row 65534, 65535, or
    65536. Even if you corrected your typo (should have said 65536), if the data
    extended to row 65536, you'd end either on Row 1 or on the last occurrence
    of a break in the data, using End(xlUP). And what if there is no data in Col
    A ... or what if the data in colums other than A extended below rows which
    Col A's data held? There are a lot of other ways to get last row. The
    quickest I know is:
    Activesheet.UsedRange.SpecialCells(xlcelltypelastcell).Row



    "Bob Sullentrup" <[email protected]> wrote in message
    news:[email protected]...
    > Folks,
    >
    > In VBA I have frequently used the formula:
    >
    > last_row = ActiveWorkbook.Sheets("Sheet1").Range("A65534").End(xlUp).Row
    >
    > to find the last cell with data in it in column A of Sheet1.
    >
    > In Visual Studio Tools for Office (C#) the equivalent expression I have
    > just
    > discovered is:
    >
    > Sheet1.get_Range("A65534",
    > Type.Missing).get_End(Excel.XlDirection.xlUp).Row
    >
    > --
    > Bob Sullentrup




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1