+ Reply to Thread
Results 1 to 15 of 15

Range("A1")(2,2) reference style doesn't work!!

  1. #1
    Forum Contributor
    Join Date
    04-24-2012
    Location
    Moscow
    MS-Off Ver
    Excel 2010
    Posts
    291

    Range("A1")(2,2) reference style doesn't work!!

    I get object related errors on the line with debug: "Run-time error '424'" or 1001. I know there is nothing wrong with the code. Comp was restarted, excel process shutted down... Have no idea what's going on. PLEASE HELP

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Range("A1")(2,2) reference style doesn't work!!

    What are you trying to do?

    i is an undefined variable and swsr is a single value, not an array. Therefore you cannot reference an element of the matrix swsr as you are trying?

  3. #3
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Range("A1")(2,2) reference style doesn't work!!

    I know there is nothing wrong with the code.
    Really? it would work if you defined i.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Range("A1")(2,2) reference style doesn't work!!

    Hi, Stephen,

    I agree on i but I doubt that a single cell would have more than 1 and 1 as limits for the bounds of the range.

    Please Login or Register  to view this content.
    @Alexxander:
    Your thread title needs an update - itīs not fitting with what you ask.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  5. #5
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Range("A1")(2,2) reference style doesn't work!!

    Holger - see what happens when you do this:
    Please Login or Register  to view this content.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Range("A1")(2,2) reference style doesn't work!!

    The ability to index outside the extents of a range is very convenient -- I use it all the time. And indices can be zero or negative, as long as the resulting reference is valid:

    Please Login or Register  to view this content.
    Last edited by shg; 11-18-2013 at 10:47 AM.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Range("A1")(2,2) reference style doesn't work!!

    Hi, Stephen,

    thanks for the clarification.

    Ciao,
    Holger

  8. #8
    Forum Contributor
    Join Date
    04-24-2012
    Location
    Moscow
    MS-Off Ver
    Excel 2010
    Posts
    291

    Re: Range("A1")(2,2) reference style doesn't work!!

    Well, i found the the mistake in my original code .
    I first set swsr to be Range("A1"), then deleted the entire column "A" and the tried to refer to swsr. Dump.

  9. #9
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Range("A1")(2,2) reference style doesn't work!!

    shg: I was thinking that 0 was invalid, as in row 0, but of course you made me realise this isn't a problem. If you don't declare i, what type does Excel assume and would that cause an error though?

  10. #10
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Range("A1")(2,2) reference style doesn't work!!

    If you run the code in post 1, the value of i is "empty" and it creates an error. The type is variant/empty on an undeclared and unused variable.

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Range("A1")(2,2) reference style doesn't work!!

    Had it been declared as a Long, it would have worked, but for the fact that it's in the first row.

  12. #12
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Range("A1")(2,2) reference style doesn't work!!

    Actually the error is because 0 implies the row above and we are starting at row 1. This does not error if you turn off option explicit:
    Please Login or Register  to view this content.

  13. #13
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Range("A1")(2,2) reference style doesn't work!!

    I don't like this code haha.

  14. #14
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Range("A1")(2,2) reference style doesn't work!!

    Again, it's very convenient. If r is the data range of a table (small t), r.Rows(0) is the header.

  15. #15
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Range("A1")(2,2) reference style doesn't work!!

    Of course, I guess it is confusing, because I would normally use .offset to achieve that and so a different base for the reference.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Open files from FTP server (works with "servername" but doesn't work with "ip address")
    By adammsu1983 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-24-2012, 04:30 PM
  2. [SOLVED] hyperlink doesn't work, "Reference is not Valid"
    By Stella2012 in forum Excel General
    Replies: 3
    Last Post: 07-30-2012, 09:52 PM
  3. [SOLVED] Why doesn't 'Range("A65000").Select' work?
    By Alan in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-22-2006, 08:20 PM
  4. Replies: 1
    Last Post: 01-13-2006, 05:09 PM
  5. Excel macro convert to VBA - doesn't work, hangs on Range("Q35").Select
    By Harold Good in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-13-2006, 04:55 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1