View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Matthew Dyer Matthew Dyer is offline
external usenet poster
 
Posts: 178
Default lastrow function help

I've been using Chip's (i believe) lastrow function for quite a while now and just ran into something strange in Office 2010:

if i have data in several columns, and a header row, and one column only has two options - AA or AB. I sort data by that column alphabetically a-z -
if i run lastrow on that sheet with no filter i get the true lastrow
if i filter only ab i get the true lastrow
if i filter only aa i get 1 as the result of lastrow?

here's the function for those unfamiliar:

Function LastRow(sh As Worksheet)
On Error Resume Next
'only looks for visible data, will not return hidden rows
'assign value for lastrow by finding
'What:="*" |ANY value
'after:=sh.range("a1") |anything after the first cell on the sheet
'Lookat:=xlPart |Match any portion of the cell value
'LookIn:=xlValues |Look in cell values instead of formulas
'SearchOrder:=xlByRows |Search by Rows, change to xlByColumns to search by Columns
'SearchDirection:=xlprevious |Search End to Beginning
'MatchCase:=False |Not Upper/Lowercase specific
'.Row |Return the Row value of that cell, change to .Column to return Column Value
LastRow = sh.Cells.Find( _
What:="*", _
After:=sh.Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlValues, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False) _
.Row
On Error GoTo 0
End Function