+ Reply to Thread
Results 1 to 2 of 2

Last used column

  1. #1
    Mitch
    Guest

    Last used column

    I need to create a named range in a worksheet where I know the upper left
    cell in the range but do not know the bottom right cell. It will be the last
    filled cell in both the column and row. How can I do it?

  2. #2
    Jim Thomlinson
    Guest

    RE: Last used column

    Here is a function for you ...

    Sub Test
    LastCell().Select
    End Sub

    Public Function LastCell(Optional ByVal wks As Worksheet) As Range
    Dim lngLastRow As Long
    Dim intLastColumn As Integer

    If wks Is Nothing Then Set wks = ActiveSheet
    On Error Resume Next
    lngLastRow = wks.Cells.Find(What:="*", _
    After:=wks.Range("A1"), _
    Lookat:=xlPart, _
    LookIn:=xlFormulas, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlPrevious, _
    MatchCase:=False).Row
    intLastColumn = wks.Cells.Find(What:="*", _
    After:=wks.Range("A1"), _
    Lookat:=xlPart, _
    LookIn:=xlFormulas, _
    SearchOrder:=xlByColumns, _
    SearchDirection:=xlPrevious, _
    MatchCase:=False).Column
    On Error GoTo 0
    If lngLastRow = 0 Then
    lngLastRow = 1
    intLastColumn = 1
    End If
    Set LastCell = wks.Cells(lngLastRow, intLastColumn)

    End Function

    --
    HTH...

    Jim Thomlinson


    "Mitch" wrote:

    > I need to create a named range in a worksheet where I know the upper left
    > cell in the range but do not know the bottom right cell. It will be the last
    > filled cell in both the column and row. How can I do it?


+ 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