Finding the last row in or length of a passed range

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,691
Office Version
  1. 365
Platform
  1. Windows
Given pratings, a range, I can find the absolute range address, the number of rows and columns, and the number of the first row and column.

Code:
?pratings.address
$D$5:$G$14

?pratings.rows.count
 10 

?pratings.columns.count
 4 

?pratings.row
 5 

?pratings.column
 4

Are there expressions that will return the number of the last row (14) and the letter or number of the last column (G or 7) in the range? I know I can extract that information from the results above, but if there is a built-in expression, I would prefer to use it.

Thanks
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
With:
Code:
[COLOR=#333333]?pratings.address
[/COLOR][COLOR=#333333]$D$5:$G$14[/COLOR]

If cell [G14] have data:

Code:
?[COLOR=#333333]pratings[/COLOR].SpecialCells(xlCellTypeLastCell).Address(0,0)
G14
?[COLOR=#333333]pratings[/COLOR].SpecialCells(xlCellTypeLastCell).Column
7
?[COLOR=#333333]pratings[/COLOR].SpecialCells(xlCellTypeLastCell).Row
14

If cell [G14] have not data:

Code:
[COLOR=#333333]?pratings.address
[/COLOR][COLOR=#333333]$D$5:$G$14[/COLOR][COLOR=#333333]
[/COLOR]?Evaluate("=Mid(""" & pratings[COLOR=#333333].address[/COLOR] & """, Find(""#"", Substitute(""" & pratings[COLOR=#333333].address[/COLOR] & """, ""$"", ""#"", 3), 1) + 1, Find(""#"", Substitute(""" & pratings[COLOR=#333333].address[/COLOR] & """, ""$"", ""#"", 4), 1) - Find(""#"", Substitute(""" & pratings[COLOR=#333333].address[/COLOR] & """, ""$"", ""#"", 3), 1)-1)")
G

'OR
?Evaluate("=Mid(""" & pratings[COLOR=#333333].address[/COLOR] & """, Find("":"", """ & pratings[COLOR=#333333].address[/COLOR] & """, 1) + 1, Len(""" & pratings[COLOR=#333333].address[/COLOR] & """) - Find("":"", """ & pratings[COLOR=#333333].address[/COLOR] & """, 1))")
$G$14
?Range(Evaluate("=Mid(""" & pratings[COLOR=#333333].address[/COLOR] & """, Find("":"", """ & pratings[COLOR=#333333].address[/COLOR] & """, 1) + 1, Len(""" & pratings[COLOR=#333333].address[/COLOR] & """) - Find("":"", """ & pratings[COLOR=#333333].address[/COLOR] & """, 1))")).Column
7
?Range(Evaluate("=Mid(""" & pratings[COLOR=#333333].address[/COLOR] & """, Find("":"", """ & pratings[COLOR=#333333].address[/COLOR] & """, 1) + 1, Len(""" & pratings[COLOR=#333333].address[/COLOR] & """) - Find("":"", """ & pratings[COLOR=#333333].address[/COLOR] & """, 1))")).Row
14
 
Upvote 0
Some options

Code:
    fisrt = pratings.Cells(1, 1).Address
    last = pratings.Cells(pratings.Rows.Count, pratings.Columns.Count).Address
 
Upvote 0
You can do this without the Cells object call...

first = pratings(1).Address

last = Pratings(Pratings.Count).Address


Thanks Rick for your contributions.


Then we would have:

Code:
    Set last = pratings(pratings.Count)
    
    lastcel = last.Address
    lastrow = last.Row
    lastcol = last.Column
 
Upvote 0
You can do this without the Cells object call...

first = pratings(1).Address

last = Pratings(Pratings.Count).Address

Excellent. I'll have to study this solution and compare with Dante's. I think I can learn a lot from that.

Thanks
 
Upvote 0
Another way
Code:
   Debug.Print "column", Split(pratings.Address, "$")(3)
   Debug.Print "Row", Split(pratings.Address, "$")(4)
 
Upvote 0

Forum statistics

Threads
1,224,747
Messages
6,180,719
Members
452,995
Latest member
isldboy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top