Consulting

Results 1 to 7 of 7

Thread: Solved: Finding the rows of a Selection

  1. #1
    VBAX Regular
    Joined
    Aug 2004
    Posts
    11
    Location

    Solved: Finding the rows of a Selection

    How do I find the last row number of a selection?

    Selection.Row seems to give me the 1st row, but I can't figure out the syntax for the count of the rows or the last row, or even the range address. (actually all I need is the last row, just trying to find something to help me calculate it)

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]
    MsgBox Selection.Row + Selection.Rows.Count - 1

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    One way:

    [VBA]Sub a()
    Dim rng As Range
    Set rng = ActiveSheet.UsedRange
    MsgBox rng(rng.Count).Row
    End Sub[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I misunderstood the question. Please ignore.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    VBAX Regular
    Joined
    Aug 2004
    Posts
    11
    Location

    solved

    perfect - thanks.

    I didnt think rows.count would work since I couldn't find it in my "watch" of the selection object.

  6. #6
    VBAX Regular
    Joined
    Aug 2004
    Posts
    11
    Location

    how do I mark this thread solved?

    how do I mark this thread solved?

  7. #7
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    Above your initial post is a drop down list headed by Thread Tools. Within that listing should be an option to Mark Thread Solved.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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