填充数组时,Excel VBA运行时错误“6”

我已经解决了这个问题。 问题与代码无关(直接)。 这与lRowvariables有关。 这个值由我的电子表格中的公式填充,然后又由另一个macros填充。 我发现我插入了一列,因此更新了错误的列。 我改变了我的代码来更新命名范围而不是实际的地址,问题就消失了。 仍然有点奇怪,这个代码失败了,因为第24行的值对我来说是有效的。

感谢所有的投入!


希望有人能帮到这里。 我最近开始尝试运行我的代码时出现错误。

运行时错误“6”

这个错误出现在这行代码中:

NewArr = Sheets("Input Sheet").Range("A" & lRow & ":BJ" & lRow).Value 

这个variables在上面被声明为:

 Dim NewArr() As Variant 

lRow评估为24,所以我们的想法是,名为NewArr的数组将填充input表范围A24:BJ24中显示的值。

我知道variables数据types可以处理非常大的数字,虽然在这一行有一些大的数字和文本等,但是没有超过400万。 (一个是3380438.98545603)。 任何想法,为什么我得到这个错误?

TIA!

我的完整的代码(直到我得到错误的地步)是:

 Private Sub BT_SUBMIT_Click() Dim NewArr As Variant Dim lRow As Long Dim lCol As Long Dim PasteRange As Range Dim bUpdated As Boolean 'Check if the user has ticked the confirm box before writing to the spreadsheet If Me.XB_CONFIRM.Value = False Then MsgBox "You must tick the confirm box to indicate you understand that " _ & "your amendments cannot be undone. Please return to the form, tick the box and " _ & "resubmit.", vbOKOnly, "Please tick confirmation box" Exit Sub End If 'Check if the user has selected either yes or no on changes frame If Me.OB_CHNGS_NO.Value = False And Me.OB_CHNGS_YES.Value = False Then MsgBox "You must select either yes or no to indicate if there are changes being made." _ & " Please correct and resubmit.", vbCritical, "Select Yes or No" Exit Sub End If 'Check if the Target Resolution Date is at least today or later and if not 'user must update If Sheets("Input Sheet").Cells(Sheets("Lookups").Range("NEW_IAR_ROW").Value, 38).Value < Now() And Me.OB_CHNGS_YES.Value = False Then MsgBox "The Target Resolution Date must be no earlier than today." _ & " Please correct and resubmit.", vbCritical, "Change Target Resolution Date" Me.OB_CHNGS_YES.Value = True Exit Sub End If 'Check if the values enterered are valid If Me.OB_CHNGS_YES Then If Control_Error("FR_AMNDMENTS") Then Exit Sub End If If (Len(Me.TB_AMNT_RES.Value) + Len(Me.TB_NO_TRNS_RES.Value) + Len(Me.TB_CMNT_RES.Value)) > 0 Then bUpdated = True If Control_Error("FR_IAR_RSVD") Then Exit Sub End If End If If (Len(Me.TB_AMNT_WO.Value) + Len(Me.TB_NO_TRNS_WO.Value) + Len(Me.TB_CMNT_WO.Value)) Then bUpdated = True If Control_Error("FR_IAR_WO") Then Exit Sub End If End If If (Len(Me.TB_AMNT_INC.Value) + Len(Me.TB_NO_TRNS_INC.Value) + Len(Me.TB_CMNT_INC.Value)) Then bUpdated = True If Control_Error("FR_IAR_INCR") Then Exit Sub End If End If If Not (bUpdated) Then MsgBox "You have not entered any changes for resolved, write offs or increases. " _ & "You must update at least one of these sections or select no changes.", vbCritical, "Error" Exit Sub End If End If lRow = Sheets("Lookups").Range("NEW_IAR_ROW").Value lCol = Sheets("Lookups").Range("TOTAL_COLUMNS").Value 'First we load the array with the current values on the sheet. NewArr = Sheets("Input Sheet").Range("A" & lRow & ":BJ" & lRow).Value Application.ScreenUpdating = False 'Then there is other code beyond this point End Sub