单元格溢出行值

Cells Overflow Row Value

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 时,我会遇到问题,如何使它允许 Long 而不是 Integer

我不确定如何定义此单元格以允许它引用大于整数的行。替代解决方案也很受欢迎!

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) 的值,都需要将变量声明为 Long,因为 32,768 溢出 Integer,如您所见。


也就是说,我强烈建议您重命名这些变量以使用有意义的标识符,这样您就不需要评论来告诉您它们代表什么。

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