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.
Bookmarks