H
Harvey Waxman
Is there a function that will return the last non-blank cell at the end of a
column range?
column range?
Harvey Waxman said:Is there a function that will return the last non-blank cell at the end of a
column range?
Domenic said:Try the following...
For numerical data:
=INDEX(A:A,MATCH(9.99999999999999E+307,A:A))
For text data:
=INDEX(A:A,MATCH(REPT("z",255),A:A))
For a range containing both text and numerical data:
=INDEX(A:A,LOOKUP(2,1/(A1:A100<>""),ROW(A1:A100)))
Hope this helps!
Harvey Waxman said:It works perfectly. Now, if I could understand exactly what it means...
Thanks
snipDomenic said:Try the following...
For numerical data:
=INDEX(A:A,MATCH(9.99999999999999E+307,A:A))
Domenic said:Actually, I would use the following formulas instead...
For numerical data:
=LOOKUP(9.99999999999999E+307,A:A)
For text data:
=LOOKUP(REPT("z",255),A:A)
For a range containing both text and numerical data:
=LOOKUP(2,1/(A1:A100<>""),A1:A100)
Hope this helps!
P.S. I'm just turning in for the night .... it's past my bedtime
.... so if nobody jumps in I'll try and explain it tomorrow.
Domenic said:[2] =LOOKUP(REPT("z",255),A:A)
REPT("z",255) is the largest text value recognized by Excel and, again,
LOOKUP returns the last text value in Column A.
Domenic said:Basically, here is how the formulas work...
JE McGimpsey said:Domenic said:[2] =LOOKUP(REPT("z",255),A:A)
REPT("z",255) is the largest text value recognized by Excel and, again,
LOOKUP returns the last text value in Column A.
minor niggle:
REPT("z",255) *is* a large text value starting with the 26 English
letters.
However, ANY string longer than 255 characters will be "larger"... For
instance, put
=REPT("A",256)
below other cells, and the last text cell before the "aaa..." will be
returned.
In most practical applications, that's not an issue, but if you have a
short paragraph (but longer than 255 characters), you'll get a bogus
answer.
This isn't really fixable using LOOKUP - while REPT() can produce a
string up to 32767 characters, the LOOKUP function can only take a
lookup value of 255 characters or less.
You can always use something like this UDF, regardless of the type of
data:
Public Function LastValue(ByVal rng As Range) As Variant
Dim vTemp As Variant
With rng.Resize(, 1)
If Application.CountA(.Cells) = 0 Then
vTemp = CVErr(xlErrNA)
ElseIf IsEmpty(.Cells(.Count).Value) Then
vTemp = .Cells(.Count).End(xlUp).Value
Else
vTemp = .Cells(.Count).Value
End If
End With
LastValue = vTemp
End Function
call as
=LastValue(A:A)
or
=LastValue(A10:A40)
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.