Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 金字塔码问题:未定义对象_Excel_Vba - Fatal编程技术网

Excel 金字塔码问题:未定义对象

Excel 金字塔码问题:未定义对象,excel,vba,Excel,Vba,当我运行这个代码块时,它会生成 运行时错误1004:应用程序定义或对象定义错误 但是VBA正在工作,调试行应该是 py.Range(py.Cells(row, coloum + level), py.Cells(row, coloum - level)).Value = "*" 如何修复它 Dim wantnum As Integer Dim py As Worksheet Dim inputs As Integer Dim row As Integer Dim coloum As Integ

当我运行这个代码块时,它会生成

运行时错误1004:应用程序定义或对象定义错误

但是VBA正在工作,调试行应该是

py.Range(py.Cells(row, coloum + level), py.Cells(row, coloum - level)).Value = "*"
如何修复它

Dim wantnum As Integer
Dim py As Worksheet
Dim inputs As Integer
Dim row As Integer
Dim coloum As Integer
Dim count As Integer
Dim level As Integer    

Set py = Sheets("sheet4")

inputs = InputBox(" Enter the pyrimad level you want")

row = 1
coloum = inputs
level = 0

For count = 0 To inputs

    py.Range(py.Cells(row, coloum + level), py.Cells(row, coloum - level)).Value = "*"
    row = row + 1
    level = level + 1

    Debug.Print Error$(count)

Next count

End Sub
请尝试以下代码:

Sub Pyramid()
    Dim wantnum As Integer
    Dim py As Worksheet
    Dim inputs As Integer
    Dim row As Integer
    Dim coloum As Integer
    Dim count As Integer
    Dim level As Integer

    Set py = Sheets("sheet4")

    inputs = InputBox(" Enter the pyrimad level you want")

    row = 1
    coloum = inputs
    level = 0

    For count = 1 To inputs

        py.Range(py.Cells(row, coloum + level), py.Cells(row, coloum - level)).Value = "*"

        row = row + 1
        level = level + 1

        'Debug.Print Error$(count)

    Next count

End Sub
请尝试以下代码:

Sub Pyramid()
    Dim wantnum As Integer
    Dim py As Worksheet
    Dim inputs As Integer
    Dim row As Integer
    Dim coloum As Integer
    Dim count As Integer
    Dim level As Integer

    Set py = Sheets("sheet4")

    inputs = InputBox(" Enter the pyrimad level you want")

    row = 1
    coloum = inputs
    level = 0

    For count = 1 To inputs

        py.Range(py.Cells(row, coloum + level), py.Cells(row, coloum - level)).Value = "*"

        row = row + 1
        level = level + 1

        'Debug.Print Error$(count)

    Next count

End Sub