There's way too much performance overhead for my liking what with all
the testing done in your code! Just thought you might appreciate the
following...
Columns(1) and Columns("A") return the same reference, so..
Dim vRef As Variant
vRef = InputBox("Enter a column letter or number")
...will return a number or string value relative to user input. So...
Columns(vRef) will evaluate to either Columns(1) OR Columns("A")!
===
Your code will fail if the user is working on an early version file in
XL2007 or later because it determines the number of rows based on
version, *NOT* the actual worksheet!
Rows.Count
..will return the number of rows on a worksheet regardless of
version. So...
lLastRow = Rows.Count.Row
...will get you the number of rows on a worksheet.
===
You use...
On Error GoTo ErrorHandler
...and so testing if an error occured there isn't required since
execution will only go there when Err.Number is not zero!
===
Sub ShowLastRow()
Dim vRef As Variant, rng As Range
vRef = Application.InputBox("Enter a column letter or number",
Type:=3) '//accept numbers or text only
If vRef = False Then Exit Sub '//user cancels
On Error GoTo ErrExit
Set rng = Cells(Rows.Count, Columns(vRef)).End(xlUp)
MsgBox rng.Address: rng.Activate
NormalExit:
Exit Sub
ErrExit:
MsgBox "Could not find the last row for column " & vRef
End Sub
--
Garry
Free usenet access at
http://www.eternal-september.org
Classic
VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.
vb.general.discussion