Results 1 to 7 of 7

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

Threaded View

  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:

    Private Sub ButtonDrawLine_Click()
    
    Worksheets("Calendar").Activate
    
    Dim LineCoordinates(1 To 2, 1 To 2) As Single
    
    With Worksheets("Calendar")
    
        LineCoordinates(1, 1) = .Range(Cells(TRow, TColumn)).Left + .Range("H4").Width / 2
        LineCoordinates(1, 2) = .Range("H4").Top + .Range("H4").Height / 2
        LineCoordinates(2, 1) = .Range("H18").Left + .Range("H18").Width / 2
        LineCoordinates(2, 2) = .Range("H18").Top + .Range("H18").Height / 2
    
    End With
    
    Worksheets("Calendar").Shapes.AddPolyline LineCoordinates
    
    MsgBox Worksheets("Calendar").Range("H4").Left + Worksheets("Calendar").Range("H4").Width / 2
    
    Cells(TRow, TColumn).Interior.Color = RGB(230, 13, 46)
    
    Unload Me
    
    End Sub
    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

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