Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 187
Default UDF to find end of range

Does anyone have code for a UDF that will return the ending cell of a
range.

I'm envisioning something like =EndAddress(A1) would return, say $A$10
if the range A1:A10 were populated.

Anyone ever create a UDF along these lines?

Thanks,

Dave

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default UDF to find end of range

If there are no embedded blanks between A1 and the last filled cell:

Range("A1").End(xlDown).Address

If there are, but there's no data below the specified range,

Cells(Rows.Count, 1).End(xlUp).Address


On Mon, 05 Nov 2007 11:30:12 -0800, Dave F wrote:

Does anyone have code for a UDF that will return the ending cell of a
range.

I'm envisioning something like =EndAddress(A1) would return, say $A$10
if the range A1:A10 were populated.

Anyone ever create a UDF along these lines?

Thanks,

Dave

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default UDF to find end of range

There is a bit on an issue with what you have asked for. By only specifying
A1 as the argument then the function needs to be made volatile to account for
when new values are added to column A. You can get around that by adding in
the entire column as the argument to the UDF. Give this a try.

Public Function EndAddress(ByVal rng As Range) As String
Dim rngLast As Range

With rng
Set rngLast = .Item(.Count).End(xlUp)
If rngLast.Row < .Item(1).Row Then Set rngLast = .Item(1)
End With
EndAddress = rngLast.Address

End Function

Use the function like this...
=EndAddress(A:A)
or
=endAddress(A5:A50)
--
HTH...

Jim Thomlinson


"Dave F" wrote:

Does anyone have code for a UDF that will return the ending cell of a
range.

I'm envisioning something like =EndAddress(A1) would return, say $A$10
if the range A1:A10 were populated.

Anyone ever create a UDF along these lines?

Thanks,

Dave


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default UDF to find end of range

Public Function EndAddress(rng As Range)
Dim r As Range, r1 As Range
Set r = rng.Areas(rng.Areas.Count)
Set r = r(r.Count)
Set r1 = r.Parent.Cells(Rows.Count, r.Column).End(xlUp)
EndAddress = r1.Address(0, 0)
End Function

would be a start.

--
regards,
Tom Ogilvy


"Dave F" wrote:

Does anyone have code for a UDF that will return the ending cell of a
range.

I'm envisioning something like =EndAddress(A1) would return, say $A$10
if the range A1:A10 were populated.

Anyone ever create a UDF along these lines?

Thanks,

Dave


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default UDF to find end of range

How about:

Function EndAddress(r As Range) As String
EndAddress = ""
For Each rr In r
If IsEmpty(rr) Then
Else
EndAddress = rr.Address
End If
Next
End Function

--
Gary''s Student - gsnu200753


"Dave F" wrote:

Does anyone have code for a UDF that will return the ending cell of a
range.

I'm envisioning something like =EndAddress(A1) would return, say $A$10
if the range A1:A10 were populated.

Anyone ever create a UDF along these lines?

Thanks,

Dave




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 187
Default UDF to find end of range

Thanks for the suggestion. Using this code I get a #VALUE! error:

Function EndAddress()
Range("A1").End(xlDown).Address
End Function

The range in this case is A1:A5 and there are no blanks in the row.

This code is entered in a module.

Thoughts?

On Nov 5, 2:56 pm, Myrna Larson
wrote:
If there are no embedded blanks between A1 and the last filled cell:

Range("A1").End(xlDown).Address

If there are, but there's no data below the specified range,

Cells(Rows.Count, 1).End(xlUp).Address



On Mon, 05 Nov 2007 11:30:12 -0800, Dave F wrote:
Does anyone have code for a UDF that will return the ending cell of a
range.


I'm envisioning something like =EndAddress(A1) would return, say $A$10
if the range A1:A10 were populated.


Anyone ever create a UDF along these lines?


Thanks,


Dave- Hide quoted text -


- Show quoted text -



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default UDF to find end of range

There is a limitation/advantage to .End(xlUp)
It ignores hidden cells.
This may or may not be what you want.

Charles
______________________
Decision Models
FastExcel 2.3 now available
Name Manager 4.0 now available
www.DecisionModels.com

"Tom Ogilvy" wrote in message
...
Public Function EndAddress(rng As Range)
Dim r As Range, r1 As Range
Set r = rng.Areas(rng.Areas.Count)
Set r = r(r.Count)
Set r1 = r.Parent.Cells(Rows.Count, r.Column).End(xlUp)
EndAddress = r1.Address(0, 0)
End Function

would be a start.

--
regards,
Tom Ogilvy


"Dave F" wrote:

Does anyone have code for a UDF that will return the ending cell of a
range.

I'm envisioning something like =EndAddress(A1) would return, say $A$10
if the range A1:A10 were populated.

Anyone ever create a UDF along these lines?

Thanks,

Dave




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 187
Default UDF to find end of range

Thanks Charles.

There are no hidden cells in the worksheets I'm working with, so that
shouldn't pose a problem.

Dave

On Nov 5, 5:26 pm, "Charles Williams"
wrote:
There is a limitation/advantage to .End(xlUp)
It ignores hidden cells.
This may or may not be what you want.

Charles
______________________
Decision Models
FastExcel 2.3 now available
Name Manager 4.0 now availablewww.DecisionModels.com

"Tom Ogilvy" wrote in message

...



Public Function EndAddress(rng As Range)
Dim r As Range, r1 As Range
Set r = rng.Areas(rng.Areas.Count)
Set r = r(r.Count)
Set r1 = r.Parent.Cells(Rows.Count, r.Column).End(xlUp)
EndAddress = r1.Address(0, 0)
End Function


would be a start.


--
regards,
Tom Ogilvy


"Dave F" wrote:


Does anyone have code for a UDF that will return the ending cell of a
range.


I'm envisioning something like =EndAddress(A1) would return, say $A$10
if the range A1:A10 were populated.


Anyone ever create a UDF along these lines?


Thanks,


Dave- Hide quoted text -


- Show quoted text -



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
Find Last cell in Range when range is date format default105 Excel Discussion (Misc queries) 5 July 7th 09 03:11 PM
VBA REQUIRED TO TAKE VALUE FROM EACH CELL FROM A RANGE AND FIND THE VALUE FROM A DIFFERENT RANGE CAPTGNVR Excel Programming 2 July 5th 07 08:13 PM
Find a range of values in a range of cells Jack Taylor Excel Worksheet Functions 20 November 25th 06 01:26 PM
Find the POSITION IN A RANGE of text in a string that matches value(s) in a range Cornell1992 Excel Programming 0 March 14th 06 07:19 PM
Find dates in a range; then sum values in that range by a criteria Anders Excel Discussion (Misc queries) 4 October 21st 05 03:41 PM


All times are GMT +1. The time now is 05:25 AM.

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"