Comments in-line
Vacuum Sealed said:
Crap, I need to proof read these things before I post em.
Hehe. Join the club said:
Repost:
My humblest of apologies to both of you as I seem to have confused
each of you.
Clif
This last very nice code works well at locating the first blank cell
down column A in "Master.xls".
Did you catch Rick's suggestion of using the Range.Find method instead?
As long as the first "blank" formula cell is the one you are looking
for, the .Find method will be much faster than the For Next loop, and I
would consider it to be much cleaner code. It's pretty obvious that Rick
has much more experience than I do, and I'm glad he joined the thread!
If there can be "blank" cells above the one you want, my code won't ever
find them because it is looking up from the bottom, where Rick's
suggested .Find is looking down from the top. I think the .Find can be
modified to look up from the bottom, by modifying the After:= and
SearchDirection:= parameters.
This worked well when I inadvertantly pasted it before the copy range
statement, but in effect it made the first blank cell of "Master.xls"
the ActiveCell which is when I realised I should have pasted it after
"History.xls" was activated.
When you are working with Active cells and Selections you need to be
*very* careful about what has the focus. After many months of dabbling
with this sort of thing, I realized that using Range objects makes it
much easier for me to explicitly define what range I am operating upon
(the $15 word is disambiguation.) (With ... End With constructs are
another way to work with explicit range objects.) Not only that, but
using range objects and temporarily turning off the user interface runs
a lot faster than using .Select and/or .Activate.
Dim myRange1 as range
Dim myRange2 as range
Dim myRange3 as range
' etc....
set myRange1 = some range of interest
set myRange2 = some other range of interest -- can be on the same or any
other sheet
then you can use myRange1.property or method, etc as self-documentation
depending on what you use as the actual variable names.
I'm not sure how important it is, but I make a practice of always
explicitly releasing objects that I instantiate in code before I exit
the procedure:
set myRange1 = Nothing
etc.
And this is probably where the confusion has been added by me.
Rick
The EntireRow.Select was to select the entire row of all Cells being
copied from the "Master.xls" to "History.xls".
So disregard the EntireRow.Select section as it turns out to be
irrelavent now that I can use the SpecialCells Set ca
What was happening prior is that when I was calling the
GetFirstBlankRow Function after "History.xls" was activated, It
assumed the embedded formulae was not a blank cell and activated the
cell it interpreted as being blank which meant it kept activating a
cell 60 or so row below the last line of populated cells.
That said...!!! It hangs on
Set ca = Columns("A").SpecialCells(xlCellTypeFormulas, 23)
Have you gotten past that error? I'm unclear from your post whether you
have gotten this working or not. If this is giving you problems,
posting the actual text of the error message will be helpful.
In the line above, Columns("A") is referring to the worksheet with the
focus. From the help on Columns: "Returns a Range object that
represents all the columns on the active worksheet. If the active
document isn't a worksheet, the Columns property fails."
Just an after thought:
This Function worked to a degree as I explained, al-be-it the formulae
was a snag
Public Function GetLastRow() As Long
Dim ExcelLastCell As Object, Lrow As Long, lLastDataRow As Long,
l As Long
Set ExcelLastCell = ActiveSheet.Cells.SpecialCells(xlLastCell)
lLastDataRow = ExcelLastCell.Row
Lrow = ExcelLastCell.Row
I "think" that [ Lrow = lLastDataRow ] would execute faster - a simple
assignment instead of a call to a property.
Do While Application.CountA(ActiveSheet.Rows(Lrow)) = 0 And Lrow
<> 1
Lrow = Lrow - 1
Loop
lLastDataRow = Lrow
GetLastRowWithData = lLastDataRow
As presented, I don't see the purpose for lLastDataRow at all - that's
just extra burden to your procedure.
End Function
Thx again for all your efforts.
Mick
Happy to help!