View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Excel VBA - Found last row number but can't select it

Certainly applicable to appropriate situations, but it can be tripped up as
well by the occasional blank row or blank column.

--
Regards,
Tom Ogilvy

"MSP77079 " wrote in message
...
All of this works as long as no one has made any extraneous entries
below your data table. But, it's going to fail if the worksheet is
not absolutely, infallibly clean.

When I have a table of data, I don't use "search for *". Nor do I use
end(xlUp). Instead, I use "CurrentRegion". It is not fooled by the
occassional blank cell, nor extraneous stuff at the end of the
datatable.

Let's say that cell "B2" is the first cell in the data table. Then,

Set myRange = Range("B2").CurrentRegion
LastRow = myRange.Cells(myRange.Cells.Count).Row
LastCol = myRange.Cells(myRange.Cells.Count).Column

worksheets("Sheet3").Range("A2:AA2").Copy _
Destination:=worksheets("Sheet2").Cells(LastRow, LastCol)


---
Message posted from http://www.ExcelForum.com/