PDA

View Full Version : Disection of Code....



YellowLabPro
09-24-2006, 04:29 AM
Hi guys...
This line of code fails:
Lrow = ws.Range(Rows.Count, "A").End(xlUp).Row

This line of code works:
Lrow = ws.Cells(Rows.Count, "A").End(xlUp).Row

Could someone offer a detailed explanation

And Secondly,
Lrow = ws.Cells(Rows.Count, "A").End(xlUp).Row
and
Lrow = ws.Cells(Rows.Count, "A").End(xlUp)
Both work.
I was reading that Value is the default property for Range-- is this similar to Row? Looking this over, it seems .Row is redundant or not necessary- if the direction is Up, I don't see how it could be columns or another range value. Please correct me if I am heading down a wrong path.

Q3-
Referring back to Q1)- is there a reference of default properties for objects?

Thanks,

YLP

johnske
09-24-2006, 05:07 AM
Hi guys...
This line of code fails:
Lrow = ws.Range(Rows.Count, "A").End(xlUp).Row

This line of code works:
Lrow = ws.Cells(Rows.Count, "A").End(xlUp).Row

Could someone offer a detailed explanation

And Secondly,
Lrow = ws.Cells(Rows.Count, "A").End(xlUp).Row
and
Lrow = ws.Cells(Rows.Count, "A").End(xlUp)
Both work.
I was reading that Value is the default property for Range-- is this similar to Row? Looking this over, it seems .Row is redundant or not necessary- if the direction is Up, I don't see how it could be columns or another range value. Please correct me if I am heading down a wrong path.

Q3-
Referring back to Q1)- is there a reference of default properties for objects?

Thanks,

YLP1) Range(Rows.Count, "A").
When you use two comma-separated strings inside the range object, both statements on either side of the comma must be a valid range.
Rows.Count returns a number, "A" returns a string, neither of which is a valid range.

2) Cells(Rows.Count, "A") refers to the value (by default) in the cell at the address A65536, it does not refer to either the row or the column separately, similarly, Cells(Rows.Count, "A").End(xlUp) refers to the value in the cell containing the last piece of data in column A - and not the row. So, no, row's not the default...

Try this MsgBox Cells(Rows.Count, "A") - you'll get a blank message, but MsgBox Cells(Rows.Count, "A").Row gives 65536. You just fluked on something... :)

Edit: As for the last question on a list of defaults. There is a list in the VBA Help files, unfortunately it's not a list in the sense that I think you mean. Defaults are listed with each property and method discussed, you just have to read through and study them all to find out what they are (also, some are not documented)... :devil2:

YellowLabPro
09-24-2006, 05:12 AM
Thanks John....
I am searching online right now for a reference library of object defaults... any idea where to locate these?

johnske
09-24-2006, 05:25 AM
Read my edit above :)

YellowLabPro
09-24-2006, 06:43 AM
1) Range(Rows.Count, "A").
When you use two comma-separated strings inside the range object, both statements on either side of the comma must be a valid range.
Rows.Count returns a number, "A" returns a string, neither of which is a valid range.

2) Cells(Rows.Count, "A") refers to the value (by default) in the cell at the address A65536, it does not refer to either the row or the column separately, similarly, Cells(Rows.Count, "A").End(xlUp) refers to the value in the cell containing the last piece of data in column A - and not the row. So, no, row's not the default...

John, very nice explanation, thanks

Bob Phillips
09-24-2006, 01:56 PM
If you never used default properties, or tried to use them, you will be a wiser man and a better coder.

YellowLabPro
09-24-2006, 05:22 PM
thanks-- at this point, I cannot find references to them anyway. I just thought it would help open some doors to seeing things differently which would help my understanding, kind of a weird quirk-- thanks for the advice-- but if you know how to locate them, it would be appreciated if you would share that info. I received an email from Chip Pearson, he too was not aware how to locate any such reference.