在工作表中循环圆形单元格,以使用VBA为每个单元格添加形状

Rol*_*olo 5 vba loops

我是VBA的新手,我正在尝试为表格中的每个第二列添加一个箭头.我收到错误:method 'range' of object '_global' failed.

我该怎么做才能解决它.

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
Run Code Online (Sandbox Code Playgroud)

Dan*_*Dan 1

删除 Range(),看起来 .Left 和 .Top 是 Cells 的属性而不是 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
Run Code Online (Sandbox Code Playgroud)