繁体   English   中英

VBA Excel上的运行时错误'1004'

[英]Run-Time Error '1004' on VBA Excel

我收到运行时错误“ 1004”(应用程序定义或对象定义的错误)。 它发生在倒数第二行代码上。

另外,有人知道如何定义在同一行代码中得到的答案吗?

Private Sub selectTable()

Dim startingRow As Integer
Dim endingRow As Integer
Dim startingColumn As Integer
Dim endingColumn As Integer
Dim selectRow As Integer
Dim selectColumn As Integer

startingRow = 13 'This is the row where the table you are sihing to select starts
startingColumn = 5 'This is the row where the table you are wishing to select starts

endingRow = 0 'Variable to hold count of how many rows of data there are
endingColumn = 0 'Variable to hold count of how many columns of data there are

While Cells(startingRow, startingColumn) <> "" 'Counts number of rows that have data
    endingRow = endingRow + 1
    startingRow = startingRow + 1
    Wend

startingRow = 13 'This is the row where the table you are sihing to select starts
startingColumn = 5 'This is the row where the table you are wishing to select starts

While Cells(startingRow, startingColumn) <> "" 'Counts number of columns that have data
    endingColumn = endingColumn + 1
    startingColumn = startingColumn + 1
    Wend

startingRow = 13 'This is the row where the table you are sihing to select starts
startingColumn = 5 'This is the row where the table you are wishing to select starts

selectRow = startingRow + endingRow - 1
selectColumn = startingColumn + endingColumn - 1

Worksheets("General Information").Range(Cells(Row1, Col1), Cells(Row3, Col3)).Select 'Selects the entire range of the desired table

End Sub
With Worksheets("General Information")
    .Range(.Cells(Row1, Col1), .Cells(Row3, Col3)).Select
End with

请参阅: 工作表和单元格的默认范围是什么?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM