Consulting

Results 1 to 5 of 5

Thread: Setting range syntax

  1. #1
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location

    Setting range syntax

    Okay, end of a very long day. Having syntax issues - yet again. The following line is giving me problems ...

    Set rng = wb.Sheet2.Range("A2:A" & wb.Sheet2.Range("A65536").End(xlUp).row)
    wb is a workbook, set as Set wb = Workbooks("WkbkName.xls"). I get a error 438, object doesn't support this property or method. Does anybody know what I'm doing here, I'm sure it's simple..

  2. #2
    VBAX Regular
    Joined
    May 2004
    Location
    Sydney, Australia
    Posts
    36
    Location
    G'day mate, just a little change needed:-


    Set rng = wb.Sheets("Sheet2").Range("A2:A" & _
    wb.Sheets("Sheet2").Range("A65536").End(xlUp).Row)

    Dan
    Last edited by Daniel Klann; 09-14-2004 at 04:02 PM. Reason: Split code over two lines

  3. #3
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hi Dan, thanks for that! So, to pick your brain here .. you're saying just change the way I'm referencing the sheet?

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    The code name of the sheet is not a collection item of the workbook. The sheet tab name is, but the code name is a class module in the VBE. If you type wb. you will see that there are no sheet code names listed. Seems odd to me, but that's the way it is.

    You can set a worksheet variable and include the workbook:


    Set ws = Workbooks("WkbkName.xls"). Sheets("Sheet2")
    Set rng = ws.Range("A2:A" & ws.Range("A65536").End(xlUp).Row)

  5. #5
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Thanks Jake, that's what I ended up going with. Interesting how that syntax plays out. I figured they (MS) would have allowed for both ways. Oh well. Thanks.

Posting Permissions

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