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