我已经解决了这个问题。问题与代码没有任何关系(直接)。它与lRow变量有关。此值由我的电子表格中的公式填充,然后由另一个宏填充。我发现我插入了一个列,因此更新了错误的列。我更改了代码以更新命名范围而不是实际地址,问题就消失了。仍然有点奇怪,这个代码失败了,因为第24行中的值对我来说似乎有效。
感谢您的所有输入!
希望有人可以在这里提供帮助。我最近在尝试运行代码时遇到错误。
此错误出现在这行代码中:
NewArr = Sheets("Input Sheet").Range("A" & lRow & ":BJ" & lRow).Value
变量在上面声明为:
Dim NewArr() As Variant
lRow正在评估为24,因此我们的想法是,将使用输入表范围A24:BJ24上显示的值填充名为NewArr的数组。
我知道变量数据类型可以处理非常大的数字,虽然这一行中有一些大数字和文本等,但没有超过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