+ Reply to Thread
Results 1 to 7 of 7

Error 1004: Application-defined or object-defined error on Range(Cells(x,y)) syntax

  1. #1
    Registered User
    Join Date
    01-03-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    4

    Error 1004: Application-defined or object-defined error on Range(Cells(x,y)) syntax

    Hi all,

    First post here, hope I can find an answer to my issue.

    I'm designing a code where I try to have it to draw a line from a user-selected cell.

    The code is:

    Please Login or Register  to view this content.
    The problem is on the fifth line of code, where I have the .Range(Cells(TRow, TColumn)) statement. I was trying building it with dummy cell references at first, but ultimately, I wanna use my variables in there, so it's dynamic.

    As soon as I change the Range("H4") to Range(Cells(x,y)), I get the error. I have tried to qualify the range better, with .Range(.Cells(4,9)) (used numbers to make sure my variables were not the source of the problem) but to no avail. I have been looking all over the web for this type of error and I always get solutions of the type I just mentioned.

    Hope someone can help!

    Best,

    Winch

    Note: The code is in a userform. Variables are provided to the form via code (I checked and they do indeed contain the correct values). The code was originally in the Module, tried to move it to the form in my troubleshooting attempts.
    Last edited by winch; 01-03-2013 at 08:22 PM. Reason: add more details

  2. #2
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Error 1004: Application-defined or object-defined error on Range(Cells(x,y)) syntax

    Without looking too closely isn't .Range(.Cells(4,9)) cell I4 not H4?

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,613

    Re: Error 1004: Application-defined or object-defined error on Range(Cells(x,y)) syntax

    range(cells(r,c).address)

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Last edited by protonLeah; 01-03-2013 at 06:34 PM.
    Ben Van Johnson

  4. #4
    Registered User
    Join Date
    01-03-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Error 1004: Application-defined or object-defined error on Range(Cells(x,y)) syntax

    Without looking too closely isn't .Range(.Cells(4,9)) cell I4 not H4?
    True, but this doesn't matter at this point, I want to use variables rather than numbers to point at the cell. Whatever number I put in, it still crashes...

  5. #5
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Error 1004: Application-defined or object-defined error on Range(Cells(x,y)) syntax

    Try using the Worksheet.Cells property and not the the Range.Cells property e.g.
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    etc.

    .. and welcome to the forum!
    Last edited by barryleajo; 01-04-2013 at 06:35 AM. Reason: Add code tags

  6. #6
    Registered User
    Join Date
    01-03-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Error 1004: Application-defined or object-defined error on Range(Cells(x,y)) syntax

    Works like a charm! Thanks, you made my day!

  7. #7
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Error 1004: Application-defined or object-defined error on Range(Cells(x,y)) syntax

    Great, glads to be of help!
    Please mark the thread as SOLVED
    Barry
    If this was helpful then please click the small star icon at the bottom left of my post. A little appreciation goes a long way.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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