Excel 金字塔码问题:未定义对象
当我运行这个代码块时,它会生成 运行时错误1004:应用程序定义或对象定义错误 但是VBA正在工作,调试行应该是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
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