我希望程序在“U34:U99”列中查找“1”。在订单号“1”上检查某些表格中的值。 例如:第一个“1”(Лист1),第二个“1”(Лист2)...... 但错误跳出(需要运行时错误424对象): 如果С.Offset(0,-5).Value = 1而C.Value = 1那么
Sub обща()
'для ситуации
Dim k As Long, n As Long
Dim C As Range
Dim Diapozon As Range
Set Diapozon = Range("U34:U99")
k = 0
n = 0
For Each C In Diapozon.Rows
If С.Offset(0, -5).Value = 1 And C.Value = 1 Then
k = k + 1
If ThisWorkbook.Sheets("Лист" & k & "").Range("R100").Value = 1 Then
n = n + 1
End If
End If
Next C
MsgBox n
End Sub
答案 0 :(得分:1)
这是可行的:
Option Explicit
Sub TestMe()
Dim k As Long
Dim n As Long
Dim C As Range
Dim Diapozon As Range
Set Diapozon = Range("A1:A10")
k = 0
n = 0
For Each C In Diapozon.Rows
If C.Offset(0, 5).Value = 1 And C.Value = 1 Then
k = k + 1
If ThisWorkbook.Worksheets("Test" & k).Range("B10").Value = 1 Then
n = n + 1
End If
End If
Next C
Debug.Print n
End Sub
我已将Ranges,Worksheet名称和MsgBox
更改为debug.print。可能的错误是您没有ListN
或其他东西......