+ Reply to Thread
Results 1 to 5 of 5

Find and select LastRow Minus 1

Hybrid View

  1. #1
    Registered User
    Join Date
    04-11-2006
    Posts
    11

    Find and select LastRow Minus 1

    I am trying to wirte a macro to find and select a range based on the first and last row (minus one row) of data on a spreadheet

    Does anyone know how to incorporate myLastRow with minus 1 row?

    Thanks in advance.


    Range("A4").Select
    myLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
    myLastColumn = Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
    myLastCell = Cells(myLastRow, myLastColumn).Address

  2. #2
    Toppers
    Guest

    RE: Find and select LastRow Minus 1

    Like?

    myLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row-1

    "Carlie" wrote:

    >
    > I am trying to wirte a macro to find and select a range based on the
    > first and last row (minus one row) of data on a spreadheet
    >
    > Does anyone know how to incorporate myLastRow with minus 1 row?
    >
    > Thanks in advance.
    >
    >
    > Range("A4").Select
    > myLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
    > myLastColumn = Cells.Find("*", [A1], , , xlByColumns,
    > xlPrevious).Column
    > myLastCell = Cells(myLastRow, myLastColumn).Address
    >
    >
    > --
    > Carlie
    > ------------------------------------------------------------------------
    > Carlie's Profile: http://www.excelforum.com/member.php...o&userid=33377
    > View this thread: http://www.excelforum.com/showthread...hreadid=533503
    >
    >


  3. #3
    Mark Lincoln
    Guest

    Re: Find and select LastRow Minus 1

    If you want myLastCell to refer to the previous row, just do this:

    myLastCell = Cells(myLastRow - 1, myLastColumn).Address

    or you can make myLastRow equal to the row you need (if you need it for
    nothing else) by:

    myLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row - 1


  4. #4
    Ronald Dodge
    Guest

    Re: Find and select LastRow Minus 1

    One thing you can do is use the End function of the Range Object, provided
    you use that worksheet more or less specifically for that list. Examples:

    What is the very last row used within column A?

    MyLastRow = Range("A65536").End(xlUp).Row

    What is the very last column used within row 4?

    MyLastColumn = Range("IV4").End(xlLeft).Column

    Note: In the first example, it's the same as if the code started with Cell
    A65536, then pressed Ctrl and the Up Arrow simultaniously. At this point,
    if you still need to know the previous row, you can use the following:

    MyLastRow = Range("A65536").End(xlUp).Row-1

    Also, the Column property is numeric, not a letter, so you would use the
    Cells Object rather than the Range Object like:

    Cells(MyLastRow,MyLastColumn)

    I would also be careful about using these without prequalifying them with a
    worksheet object as that can lead into some unwanted issues.

    --
    Ronald R. Dodge, Jr.
    Production Statistician
    Master MOUS 2000

    "Carlie" <Carlie.26f87n_1145298302.5495@excelforum-nospam.com> wrote in
    message news:Carlie.26f87n_1145298302.5495@excelforum-nospam.com...
    >
    > I am trying to wirte a macro to find and select a range based on the
    > first and last row (minus one row) of data on a spreadheet
    >
    > Does anyone know how to incorporate myLastRow with minus 1 row?
    >
    > Thanks in advance.
    >
    >
    > Range("A4").Select
    > myLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
    > myLastColumn = Cells.Find("*", [A1], , , xlByColumns,
    > xlPrevious).Column
    > myLastCell = Cells(myLastRow, myLastColumn).Address
    >
    >
    > --
    > Carlie
    > ------------------------------------------------------------------------
    > Carlie's Profile:

    http://www.excelforum.com/member.php...o&userid=33377
    > View this thread: http://www.excelforum.com/showthread...hreadid=533503
    >




  5. #5
    Registered User
    Join Date
    04-11-2006
    Posts
    11
    Thanks guys. I went for the:

    myLastCell = Cells(myLastRow - 1, myLastColumn).Address

    and works fine.

+ 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