Results 1 to 4 of 4

Auto Determine Range to pass to vlookup

Threaded View

  1. #1
    Registered User
    Join Date
    08-17-2010
    Location
    Silver City, New Mexico
    MS-Off Ver
    Excel 2010
    Posts
    2

    Auto Determine Range to pass to vlookup

    Hello all,

    I'm trying to use vba to determine the range of a worksheet so that the range includes all data on the sheet.

    I've found the following code to determine the bottom, right most cell

    Function FindLastCell() As String
    
    Dim LastColumn As Integer
    
    Dim LastRow As Long
    
    Dim LastCell As Range
    
    Dim rngResult As String
    
        If WorksheetFunction.CountA(Cells) > 0 Then
    
            'Search for any entry, by searching backwards by Rows.
    
            LastRow = Cells.Find(What:="*", After:=[a1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
            'Search for any entry, by searching backwards by Columns.
    
            LastColumn = Cells.Find(What:="*", After:=[a1], SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    
            strResult = Cells(LastRow, LastColumn).Address
    
            FindLastCell = rngResult
            
        End If
    
    End Function
    The problem is that the function returns a string, not a range reference.
    i.e. if the 'ctrl-end' keystroke were to take me to cell 'AM68' the function returns a string
    '$AM$68'.

    It seems to me it should be a trivial process to turn the info into a range object, but I'm really struggling here. Any help would be appreciated.

    Once I have the range I want to replace the hard-coded range reference is the code below

    strResult = Application.VLookup(strBlendNum, Range("a1:am68"), intBlendColorColumn, False)
    Thanks in advance for your help.
    Last edited by captlogic; 08-17-2010 at 02:39 PM. Reason: SOLVED!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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