C
crferguson
I wrote a brief function for returning the actual last row in a
worksheet regardless of empty, formerly used rows. Neither
"ActiveSheet.UsedRange.Rows.Count" nor "Cells(Rows.Count,
1).End(xlUp).Row" work consistently enough to be 100% reliable.
Here's the function I came up with that seems to work pretty well. I
know it takes a little more processing than the other two methods, but
if you're more concerned about accuracy then this should work for you:
Public Function GetRowCount() As Double
'gets a count of the used rows in a worksheet
'This is a literal count and DOES NOT take
'empty rows into consideration
Dim dX As Double, dY As Double, dZ As Double
Dim dTemp As Double, dResults As Double
dX = ActiveSheet.UsedRange.Rows.Count
dY = ActiveSheet.UsedRange.Columns.Count
For dZ = 1 To dY
dTemp = Cells(Rows.Count, dZ).End(xlUp).Row
If dTemp > dResults Then dResults = dTemp
Next
GetRowCount = dResults
End Function
Of course I'm open to better, more efficient ways of doing this![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Thanks!
Cory
worksheet regardless of empty, formerly used rows. Neither
"ActiveSheet.UsedRange.Rows.Count" nor "Cells(Rows.Count,
1).End(xlUp).Row" work consistently enough to be 100% reliable.
Here's the function I came up with that seems to work pretty well. I
know it takes a little more processing than the other two methods, but
if you're more concerned about accuracy then this should work for you:
Public Function GetRowCount() As Double
'gets a count of the used rows in a worksheet
'This is a literal count and DOES NOT take
'empty rows into consideration
Dim dX As Double, dY As Double, dZ As Double
Dim dTemp As Double, dResults As Double
dX = ActiveSheet.UsedRange.Rows.Count
dY = ActiveSheet.UsedRange.Columns.Count
For dZ = 1 To dY
dTemp = Cells(Rows.Count, dZ).End(xlUp).Row
If dTemp > dResults Then dResults = dTemp
Next
GetRowCount = dResults
End Function
Of course I'm open to better, more efficient ways of doing this
Thanks!
Cory