![]() |
#22
|
||||
|
||||
![]()
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)") Code:
Set cz = Range("E2").End(xlDown) 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. |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Formatting contents after Tab of continuous lines or formatting specific area of word | pawii | Word | 1 | 05-12-2014 05:24 AM |
macros | stebrownsword | Word VBA | 0 | 08-28-2013 01:16 AM |
![]() |
anju16saini | Word VBA | 1 | 03-11-2013 04:15 AM |
![]() |
WaltR | Word VBA | 8 | 05-15-2012 06:28 PM |
Macros | nore | Outlook | 0 | 06-01-2011 04:39 PM |