View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Keith R[_2_] Keith R[_2_] is offline
external usenet poster
 
Posts: 37
Default Locating end of used range- not returning expected value

Thanks to all (John, Jim, Bill, and JLG) for the quick response. I've
adapted some of the code provided, and will try to understand the Find
statement a little better as well- I've used the LastRow procedure without
problem for years, and until I fully understand the conditions that resulted
in the incorrect value, I won't know how many of my workbooks from the past
few years are at risk. <sinking feeling

Thanks for the help though, it looks like this project can move forward.

Best,
Keith

"John Bundy" (remove) wrote in message
...
use this and see how it works, change the "A" if that is not where the
data is
My_LastRow=sheets(4).cells(rows.count,"A").end(xlu p).row

--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"Keith R" wrote:


I have code used to append new records (rows) on sheet 4. In the past, I
use
the lastrow procedure (below, from this newsgroup) to find the last row
where I can add new data. however, in this particular case, it keeps
trying
to add my data near the top of the worksheet. So I used the rows.count to
start troubleshooting, and got the correct value there even though the
lastrow procedure is still at the top of the sheet. I have saved, closed,
and re-opened the workbook, to no avail.

Any ideas why these two would return different values?

Thanks,
Keith
XP/XL2003

(misc code deleted)

My_LastRow = Sheet4.Cells.Find(What:="*", After:=[A1],
SearchDirection:=xlPrevious).Row
MsgBox Sheet4.UsedRange.Rows.Count
'returns a value of 77, which is accurate
MsgBox My_LastRow
'returns a value of 2, then after adding a record it returns a
value
of 3.