单元格溢出行值

时间:2016-06-22 15:29:07

标签: excel vba overflow

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

enter image description here 使用上面的代码,当单元格行值大于32,768时,我遇到问题,如何允许Long而不是Integer

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

1 个答案:

答案 0 :(得分:1)

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