I
love that you jump the gun and try it yourself. You may remember my saying, or you may have divined from the extreme length and verbosity of my emails, that I'm more about teaching than I am about just doing it.
I gotta run out in about 20 minutes, but I thought I should come back and maybe chime in a little if I can. Let's take a look:
Code:
SelectRange = ("E2.End(xlDown)")
I wouldn't expect this to work. What it does is create a variable named SelectRange and tries to set it equal to "E2.End(xlDown)", which is a valid statement but doesn't do what I'm sure you meant to do. Anything in quotes is a character string, you see, including that. What you want is not the letters that spell out "E2.End(xlDown)", but the actual result of E2.End(xlDown)—assuming that E2 is a valid Cell or Range in Excel. Your subsequent attempt is better:
Code:
Set cz = Range("E2").End(xlDown)
That starts with Range("E2") (where "E2", in quotes, describes the Range that you want Excel to work with), which gives you cell E2; then to E2 it does End(xlDown), which gets you the cell that would result if you manually did <End>,<Down> from E2 in Excel. So far, so good.
Then you said "SelectRange = cz", which I expect will work but not the way you think. Here's
An Important Fact: When you're setting SelectRange to a simple value, such as 2 or "Sub-Phase", you can use a statement with just an equal sign. But when you want to point to an
object, you must use Set, ie "Set SelectRange = cz".
So what's an "object"? Well, let's think about a cell for a moment: A cell is not just the value that's in it; it has many other properties as well. E2 in the worksheet I'm looking at has a value (41771), but it also has a font (Calibri), a font size (11), some color information, several borders (Top, Bottom, Left and Right), a format ("ddd, mmm dd", which causes it to display 41771 as "Mon, May 12") and a ton of other things that you don't normally think about until you need to change it. Each of these "properties" can be manipulated because cz is not just the value of the cell ("Mon, May 12") but the whole cell "object", containing all those properties and also a number of things you can
do with the cell (called "methods") such as End(xlDown).
Cz points to cell E2; if you had set "Set SelectRange = cz", Excel would have understood that you wanted SelectRange to point to cell E2 as well. But you said "SelectRange = cz", without the "Set" command, so Excel supposed you wanted to assign
some property of cz to SelectRange. You could, for example, have said "SelectRange = cz.Font.Bold", and SelectRange would then be False (because the value isn't in a bold font). Or you could have said "SelectRange = cz.Row", which would have set SelectRange to 2 (the row number).
But you didn't specify the property that you wanted, so instead of getting upset, Excel used the
default property. The default property of a cell is its value, ie "SelectRange = cz.Value". So I expect that SelectRange became "Mon, May 12".
Now, I approve
very much of you playing with this and asking questions, and I want to answer all of them. But I have to run to a meeting, so I'll finish your questions and take more when I get back, maybe late tonight.