您好我一直得到同样的错误。工作表(4).Cells(Row_Pos,8)引用值为True或False的行。我也尝试使用1和0而不是True或False,但它仍然不起作用。
Sub AddNonStockIncomings()
Dim Row_Pos As Long
Dim ABJ_Val_Col As Integer
Dim JOS_Val_Col As Integer
Dim MIU_Val_Col As Integer
Dim YOL_Val_Col As Integer
Dim Tot_count_OT_OP As Integer
Dim Tot_count_INV As Integer
Item_Code_Col = 1 'OT OP Pivot
ABJ_Val_Col = 2 'OT OP Pivot
JOS_Val_Col = 3 'OT OP Pivot
MIU_Val_Col = 4 'OT OP Pivot
YOL_Val_Col = 5 'OT OP Pivot
Row_Pos = 3 'OT OP Pivot
I = 1
Tot_count_INV = Worksheets(3).Columns(1).SpecialCells(2).Count + 3
Tot_count_OT_OP = Worksheets(4).Columns(1).SpecialCells(2).Count
'MsgBox (Tot_count_INV)
'MsgBox (Tot_count_OT_OP)
Do While Row_Pos >= Tot_count
**If Worksheets(4).Cells(Row_Pos, 8).Value = True Then**
Worksheets(4).Cells(Row_Pos, Item_Code_Col).Copy Worksheets(5).Cells(Tot_count_OT_OP, 1)
End If
Row_Pos = Row_Pos + 1
Loop
'Add the reset of values
End Sub
强制布尔结果。
If cbool(Worksheets(4).Cells(Row_Pos, 8).Value) Then
对于所有意图和目的,布尔值False为零。通过严格的定义,任何非假的都是真的。在数学或数字比较中使用时,False在工作表或VBA中为零(0),但True在工作表上为1(1),在VBA中减1(-1)。
您不需要将布尔值与True或False进行比较。这就像问If True = True then it is True
。您可以直接使用标准;例如If Worksheets(4).Cells(Row_Pos, 8).Value Then
。
你不应该直接使用正整数或负整数作为真/假布尔值。将每个包装在一个CBool转换包装器中。在使用And运算符堆叠条件时,这一点尤为重要。 VBA的And运算符是按位的,而(2和3)是True,(2和4)是False。