运行时错误6:溢出-Excel VBA

运行时错误6:溢出-Excel VBA,vba,excel,Vba,Excel,你知道为什么会出现运行时错误6:溢出吗 Sheets("Raw data").Select Dim lastrow2 As Integer Dim lastcol2 As Integer lastcol2 = Cells(1, Columns.Count).End(xlToLeft).Column lastrow2 = Cells(Rows.Count, 1).End(xlUp).Row Range(Cells(1, 1), Cells(lastrow2, lastcol2)).Name =

你知道为什么会出现运行时错误6:溢出吗

Sheets("Raw data").Select
Dim lastrow2 As Integer
Dim lastcol2 As Integer

lastcol2 = Cells(1, Columns.Count).End(xlToLeft).Column
lastrow2 = Cells(Rows.Count, 1).End(xlUp).Row

Range(Cells(1, 1), Cells(lastrow2, lastcol2)).Name = "RawData"

我在不同的工作表上使用了完全相同的vbs代码,运行良好。我所做的只是将变量重命名为lastrow2和lastcol2。我认为是最后一行给了我问题。

声明为Long而不是Integer,看看这是否解决了问题。使用
Integer
类型没有什么好处,使用
Long
代替。我对``m=WorksheetFunction.CountA(Sheets(“FundedAmounts”).Columns(1))也有类似的问题``并将m定义为长而不是整数,解决了我的问题。