+ Reply to Thread
Results 1 to 2 of 2

Find Last Cell in Column, Select all cells above it

  1. #1
    Registered User
    Join Date
    08-24-2004
    Posts
    14

    Question Find Last Cell in Column, Select all cells above it

    Hi,

    Can someone please provide me with code that will allow me to find the last cell in a column and then select all cells above it. Or just select cells in a column from the 1st cell to the last cell that has information in it. ( I don't want to highlight everything to cell 65536).

    THANKS

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello MayDay,

    Here is a macro that does what you want.
    _________________________________________________________________

    Public Sub SelectColumn(Cell_Address As Range)

    Dim MyRange As Range
    Dim Col As Integer
    Dim Row As Long
    Dim LastRow As Long
    Dim WksName As String

    Set MyRange = Cell_Address
    Col = MyRange.Column
    Row = MyRange.Row


    'Find the Last Non Blank Row in the Column
    LastRow = MyRange.Cells(Rows.Count, Col).End(xlUp).Row

    'Select All Cells in the Column from the First to the Last
    WksName = MyRange.Parent.Name
    With Worksheets(WksName)
    .Select
    .Range(Cells(Row, Col).Address & ":" & Cells(LastRow, Col).Address).Select
    End With


    'Release the Object from Memory
    Set MyRange = Nothing

    End Sub

    _________________________________________________________________

    Using the Macro:
    For this example the column is "A" and the rows used are 1 to 25. The cells in the range are non blank. The active worksheet is "Sheet1".

    SelectColumn Cell_Address:=Range("A1")
    SelectColumn Cell_Address:=Range("A1:A10")
    SelectColumn Cell_Address:=Range("A4:C16")
    SelectColumn Cell_Address:=Range("A100")


    All of the above statements will select the Range A1 to A25. The macro automatically finds the first and last cells of the first column in the Range.

    Hope you find this useful,
    Leith Ross

+ 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