键入不匹配错误,在Excel VBA中声明范围变量

时间:2016-04-19 02:06:32

标签: vb.net excel vba basic

这应该是一个简单的修复,但我已经搜索和搜索,无法找出问题所在。

我收到"运行时错误13:输入错误":

Dim rng As Range    
Dim endRW As Integer, endCol As Integer
endRW = 30
endCol = 10
Set rng = Sheets("Sheet1").Range(Sheets("Sheet1").Cells(2,3),Sheets("Sheet1").Cells(endRW,endCol)) 

^^^最后一行导致错误^^^^

2 个答案:

答案 0 :(得分:0)

尝试

Set rng = Sheets("Sheet1").Range(Cells(2, 3), Cells(endRW, endCol))

证据。

enter image description here

答案 1 :(得分:0)

试试这个

Sub temp()
    Dim rng As Range
    Dim endRW As Long, endCol As Long
    endRW = 30
    endCol = 10
    Set rng = Worksheets("Sheet1").Range(Cells(2, 3), Cells(endRW, endCol))
End Sub