Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Modify Function to Return Value

I copied the following code from this group to determine the range of
nonblank values on a sheet. It works beautifully. I would like to
modify the function to return not only the range, but also the
RealLastRow. Any help would be appreciated!

Function GetRealLastCell(sh As Worksheet) As Range
Dim RealLastRow As Long
Dim RealLastColumn As Long
On Error Resume Next
RealLastRow = _
sh.Cells.Find("*", sh.Range("A1"), , , xlByRows, xlPrevious).Row
RealLastColumn = _
sh.Cells.Find("*", sh.Range("A1"), , , xlByColumns,
xlPrevious).Column
Set GetRealLastCell = sh.Cells(RealLastRow, RealLastColumn)
End Function

Thanks.

Connie

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Modify Function to Return Value

Function GetRealLastCell(sh As Worksheet, ByRef LastRow As Long, LastCol As
Long) As Range
Dim RealLastRow As Long
Dim RealLastColumn As Long
On Error Resume Next
RealLastRow = _
sh.Cells.Find("*", sh.Range("A1"), , , xlByRows, xlPrevious).Row
RealLastColumn = _
sh.Cells.Find("*", sh.Range("A1"), , , xlByColumns, xlPrevious).Column
Set GetRealLastCell = sh.Cells(RealLastRow, RealLastColumn)
LastRow = RealLastRow
LastCol = RealLastColumn
End Function

Sub TestGetRealLastCell()
Dim i As Long, j As Long
Dim rng As Range

Set rng = GetRealLastCell(ActiveSheet, i, j)
MsgBox "Lastrow = " & i & vbNewLine & "Lastcol = " & j
End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Connie" wrote in message
oups.com...
I copied the following code from this group to determine the range of
nonblank values on a sheet. It works beautifully. I would like to
modify the function to return not only the range, but also the
RealLastRow. Any help would be appreciated!

Function GetRealLastCell(sh As Worksheet) As Range
Dim RealLastRow As Long
Dim RealLastColumn As Long
On Error Resume Next
RealLastRow = _
sh.Cells.Find("*", sh.Range("A1"), , , xlByRows, xlPrevious).Row
RealLastColumn = _
sh.Cells.Find("*", sh.Range("A1"), , , xlByColumns,
xlPrevious).Column
Set GetRealLastCell = sh.Cells(RealLastRow, RealLastColumn)
End Function

Thanks.

Connie



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Modify Function to Return Value

Hi
The easiest thing would be to do this in the calling sub;

Set mycell = GetRealLastCell(mysheet)
RealLastrow = mycell.Row

Saves you creating a seperate function.
regards
Paul

Connie wrote:
I copied the following code from this group to determine the range of
nonblank values on a sheet. It works beautifully. I would like to
modify the function to return not only the range, but also the
RealLastRow. Any help would be appreciated!

Function GetRealLastCell(sh As Worksheet) As Range
Dim RealLastRow As Long
Dim RealLastColumn As Long
On Error Resume Next
RealLastRow = _
sh.Cells.Find("*", sh.Range("A1"), , , xlByRows, xlPrevious).Row
RealLastColumn = _
sh.Cells.Find("*", sh.Range("A1"), , , xlByColumns,
xlPrevious).Column
Set GetRealLastCell = sh.Cells(RealLastRow, RealLastColumn)
End Function

Thanks.

Connie


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Modify search function Dinesh Excel Worksheet Functions 3 March 18th 09 02:26 AM
How a function can modify a value from some cells ? Cristian Excel Programming 5 January 3rd 06 08:10 PM
Can I modify a Hyperlink with a function? barrfly Excel Discussion (Misc queries) 7 June 2nd 05 12:03 AM
Modify cell from function Jason Callas Excel Programming 3 November 6th 03 05:08 PM
to modify cells from a function Pierre Laporte Excel Programming 1 July 10th 03 02:11 PM


All times are GMT +1. The time now is 05:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"