Consulting

Results 1 to 8 of 8

Thread: Select the lastrow using the active cell

  1. #1

    Select the lastrow using the active cell

    How can I select a range using the activecell & lastrow or offset & lastrow?


  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    With ActiveCell

    .Resize(.End(xlDown).Row - .Row + 1).Select
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular n8Mills's Avatar
    Joined
    Sep 2006
    Location
    Washington State
    Posts
    54
    Location

    or...

    ...or perhaps:

    [vba]Range(ActiveCell, ActiveCell.End(xlDown)).Select[/vba]

    ...or If you want to use a variable you can do this:

    [vba]Dim lastRow as Long

    lastRow = ActiveCell.End(xlDown).Row

    Range(ActiveCell, ActiveCell.Offset(lastRow, 0)).Select[/vba]

  4. #4

    Sorry I didnt explain that right

    I need to use the activecel and lastrow, but the lastrow based on column A if that makes sense

     
     
                Dim lastrow As Long
                lastrow = Cells(Rows.Count, "A").End(xlUp).Row
     
    range("b2:b" & lastrow)
    but i want be able to say

     
          Dim lastrow As Long
                lastrow = Cells(Rows.Count, "A").End(xlUp).Row
     
    Activecell & Lastrow

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    The clues were all there

    [vba]

    Dim LastRow As Long

    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    With ActiveCell

    .Resize(LastRow - .Row + 1).Select
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6

    thank you

    thanks, again for all the help

  7. #7
    VBAX Regular n8Mills's Avatar
    Joined
    Sep 2006
    Location
    Washington State
    Posts
    54
    Location

    =)

    ...or this way:

    [vba]Dim LastRow As Long

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

    Range(ActiveCell.Address & "," & Range("B" & LastRow).Address).Select[/vba]
    ... for those of us who have never touched .Resize or .Count before.

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by n8Mills
    ...or this way:

    [vba]Dim LastRow As Long

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

    Range(ActiveCell.Address & "," & Range("B" & LastRow).Address).Select[/vba]
    ... for those of us who have never touched .Resize or .Count before.
    You might want to try that!
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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