ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   First and Last cell of a named range (https://www.excelbanter.com/excel-programming/309829-first-last-cell-named-range.html)

Steven K

First and Last cell of a named range
 
Hello,

How do you determine what the first and last cell of a named range and get
its value? Can you use the offset function with this?

--
Thanks in advance,

Steven



Jim Cone

First and Last cell of a named range
 
Steven,
If your named range is named "MyRange" then this is one way...
'-------------------------------
Sub GetNamedRangeValues()
Dim x As Long
Dim y As Variant

x = Range("MyRange").Count
y = "Last cell value is " & Range("MyRange")(x).Value
MsgBox y

y = Range("MyRange")(1).Value
MsgBox "First cell value is " & y
End Sub
'-----------------------------------

Regards,
Jim Cone
San Francisco, CA

"Steven K" wrote in message ...
Hello,
How do you determine what the first and last cell of a named range and get
its value? Can you use the offset function with this?
Thanks in advance,
Steven



Norman Jones

First and Last cell of a named range
 
Hi Steven,

Assuming that the named range is a single area range:

Sub Tester03()
Dim Rng As Range
Dim FirstCell As Range, LastCell As Range

Set Rng = Range("A1:H2")
Set FirstCell = Rng(1)
Set LastCell = Rng(Rng.Count)

'Return address and values of first and last cells
MsgBox "The first cell (" & FirstCell.Address & ") = " _
& FirstCell.value & vbNewLine & _
"The last cell (" & LastCell.Address _
& ") = " & LastCell.value
End Sub


---
Regards,
Norman



"Steven K" wrote in message
...
Hello,

How do you determine what the first and last cell of a named range and get
its value? Can you use the offset function with this?

--
Thanks in advance,

Steven






All times are GMT +1. The time now is 04:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com