Consulting

Results 1 to 7 of 7

Thread: Disection of Code....

  1. #1

    Disection of Code....

    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

  2. #2
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by YellowLabPro
    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
    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...

    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)...
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  3. #3
    Thanks John....
    I am searching online right now for a reference library of object defaults... any idea where to locate these?

  4. #4
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Read my edit above
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  5. #5
    Quote Originally Posted by johnske
    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

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    If you never used default properties, or tried to use them, you will be a wiser man and a better coder.

  7. #7
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •