单元溢出行值

Sub InsertRow() Call BlankColumns 'Call DeleteZeros 'normalizes the data extracted from QM QSRs 'If Columns included in QSR Change, THe column references will have to be adjusted Dim lastcol As Integer 'Idenfies How many Questions are in Dataset Dim r2a As Long 'Row to copy Dim nr As Integer '# of people to copy Dim r2s As Integer 'will copy each data set for however many questions there is Dim R As Integer 'Counts how many people are in the dataset R = Range("A4", Range("A4").End(xlDown)).Rows.Count With ActiveSheet lastcol = .Cells(1, .Columns.Count).End(xlToLeft).Column - 6 r2a = (lastcol / 2) - 2 r2s = (lastcol / 2) End With For nr = 0 To R Cells(((nr * r2s) + 4), 1).EntireRow.Copy Range(ActiveCell, ActiveCell.Offset((r2a), 0)).EntireRow.Insert Shift:=xlDown Next nr Call pasteanswers Call PasteActivityCode Question = MsgBox("Upload information to Database?", vbYesNo + vbQuestion, "Database Upload") If Question = vbYes Then Call SaveWorkbook Call ExportData Else End If End Sub 

错误正在发生

 Cells(((nr * r2s) + 4), 1).EntireRow.Copy 

在这里输入图像说明 随着上面的代码,我有问题,当单元格的行值大于32,768,我如何使这允许长而不是整数

我不知道如何定义这个单元格,以允许它引用大于整数的行。 替代解决scheme也表示赞赏!

 Dim nr As Integer '# of people to copy Dim r2s As Integer 'will copy each data set for however many questions there is Dim R As Integer 'Counts how many people are in the dataset 

改成:

 Dim nr As Long Dim r2s As Long Dim R As Long 

无论何时处理工作表行,或任何不符合16位整数( Integer )的最大值的值,都需要将variables声明为Long ,因为您已经注意到32,768溢出了Integer


也就是说,我会热烈地build议你重命名这些variables来使用有意义的标识符 ,这样你就不需要评论来告诉你它们代表什么了。

 Dim lastColumn As Long Dim rowToCopy As Long Dim nbPeopleToCopy As Long Dim r2s As Long 'sorry, not clear from comment or usage Dim nbRows As Long