I'm having a problem applying a loop for building rectangles in a spreadsheet, I'm getting error 1004,
Run-time error '1004':
Application-defined or object-defined error
On line:
Leftmargin = ThisWorkbook.Worksheets(2).Range(Cells(1, 1)).Left
I have no idea why this doesn't work. I would also want to switch to cells function with the rest of the parameters as I need to loop over 450 positions to build rectangles as for cards. I'm asking for explanation on the topic so that I can understand the cause of failure.
Dim sh As Shape
Dim Leftmargin
Leftmargin = ThisWorkbook.Worksheets(2).Range(Cells(1, 1)).Left
Leftmargin = Leftmargin + 2
Set sh = ThisWorkbook.Worksheets(2).Shapes.AddShape( _
Type:=msoShapeRoundedRectangle, _
Left:=Leftmargin, _
Top:=ThisWorkbook.Worksheets(2).Range("A1").Top + 2, _
Width:=ThisWorkbook.Worksheets(2).Range("A1:E1").Width - 4, _
Height:=ThisWorkbook.Worksheets(2).Range("A1:A10").Height - 4)