2012-11-14 20 views
5

我是相當新的VBA每個單元,並正在試圖箭頭在表添加到每個第二列。我收到錯誤:method 'range' of object '_global' failed環流式圓形細胞在工作表中添加圖形,使用VBA

我應該怎麼做才能修復它。

Sub loop1() 
    'Loop round range P6:AA10 
    Dim i As Integer 
    Dim j As Integer 
    Dim k As Integer 


    For i = 9 To 14 
     For j = 6 To 10 
      k = (i * 2) - 1 
      ActiveSheet.Shapes.AddShape(msoShapeRightArrow, Range(Cells(j, k)).Left + 2, _ 
       Range(Cells(j, k)).Top + 3, 15, 10).Select 
     Next j 
    Next i 
End Sub 

回答

1

刪除Range(),看起來像.Left,而.Top是Cells not Range對象的屬性。此代碼在Excel 2010上爲我運行:

Sub loop1() 
    'Loop round range P6:AA10 
    Dim i As Integer 
    Dim j As Integer 
    Dim k As Integer 


    For i = 9 To 14 
     For j = 6 To 10 
      k = (i * 2) - 1 
      ActiveSheet.Shapes.AddShape(msoShapeRightArrow, Cells(j, k).Left + 2, _ 
       Cells(j, k).Top + 3, 15, 10).Select 
     Next j 
    Next i 
End Sub 
+0

這工作完美,謝謝丹! – Rolo