将内容从一张纸复制到另一张时出错

我试图连接工作表CurrentDistribution与工作表distribution1 。 为此,我查看distribution1的最后一行,并在最后一行之后复制CurrentDistribution的内容。

 LastCellCurrentDistribution = FindLastCell(CurrentDistribution) LastCellDistribution1 = FindLastCell("distribution1") LastRowInDistribution1 = Right(LastCellDistribution1, Len(LastCellDistribution1) - 1) Sheets(CurrentDistribution).Range("A4:" + LastCellCurrentDistribution).Copy Sheets("distribution1").Range("A" + CStr((CInt(LastRowInDistribution1) + 1))) 'i only wany the row (number), not the column (letter) Sheets(CurrentDistribution).Delete 

现在问题是,当我尝试这样做时,我得到这个错误: 'Run-time error '6': Overflow' 。 我用debugging器,发现它的第四行复制引发这个错误的东西。 任何想法是什么问题,我该如何解决它?

我想象你需要声明variablesLastCellCurrentDistribution LastCellDistribution1 LastRowInDistribution1长,因为整数不能处理大于32,000的值。

尝试像下面这样声明它们:

 Dim LastCellCurrentDistribution As Long Dim LastCellDistribution1 As Long Dim LastRowInDistribution1 As Long 

看起来像我的工作表是如此之大,INTtypes不能处理我的最后一个单元格号码。 所以replace:

 Sheets(CurrentDistribution).Range("A4:" + LastCellCurrentDistribution).Copy Sheets("distribution1").Range("A" + CStr((CInt(LastRowInDistribution1) + 1))) 'i only wany the row (number), not the column (letter) 

 Sheets(CurrentDistribution).Range("A4:" + LastCellCurrentDistribution).Copy Sheets("distribution1").Range("A" + CStr(LastRowInDistribution1 + 1)) 'i only wany the row (number), not the column (letter)