2014-07-03 222 views
0

我想將紙張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'。我用調試器,發現它的第四行復制了引發這個錯誤的東西。任何想法是什麼問題以及如何修復它?

回答

0

看起來像我的工作是如此之大,INT類型不能處理我的最後一個單元格數。所以更換:

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) 
1

想象一下,由於整數不能處理大於32,000的值,因此您需要聲明變量LastCellCurrentDistributionLastCellDistribution1LastRowInDistribution1

嘗試宣告他們象下面這樣:

Dim LastCellCurrentDistribution As Long 
Dim LastCellDistribution1 As Long 
Dim LastRowInDistribution1 As Long 
相關問題