好的所以我一直试图拿出一些东西来运行它。
基本上我需要在Sheet 2中的A列上循环一个值,对于在表1中找到它所需的每个值,然后根据H列中的标识符(4个变量)向单元格添加计数,如果它符合一个标准,然后可能需要检查列K以了解哪个值。
例如:
从工作表2第2行开始,编号为“123456789”,在工作表1中查找在B列中编号为“123456789”的行(因此在B *中找到) 如果H *有一个值,那么它需要在表2的正确列中为该数字添加一个值给记录器。如果H * =某个标准,则需要检查K列中的条件,然后将该值添加到正确的列。 我完全迷失了如何设置它。 任何帮助都会很棒,非常感谢
乔恩
代码现在如下: Sub Status_Track()
Dim a As Long 'topic number
Dim Z As Integer
Dim R As Integer
Dim i As Integer
Dim S As Integer
Dim D As Integer
Worksheets("RAW").Activate
R = Cells(Rows.Count, 2).End(xlUp).Row
C = Cells(1, Columns.Count).End(xlToLeft).Column
Z = 0
i = 2
Do Until i > R
'ident
If Cells(i, 2) = Worksheets("Data").Cells(i, 2) And (Cells(i, 13) = "ERKA")Then
Z = Cells(i, 6) + 1
Worksheets("RAW").Cells(i, 6).Value = Z
Else
If Cells(i, 2) = Worksheets("Data").Cells(i, 2) And (Cells(i, 13) = "INBA") Then
'Inba
Z = Cells(i, 7) + 1
Worksheets("RAW").Cells(i, 7).Value = Z
Else
If Cells(i, 2) = Worksheets("Data").Cells(i, 2) And (Cells(i, 13) = "ABGE") Then
'Abge
Z = Cells(i, 8) + 1
Worksheets("RAW").Cells(i, 8).Value = Z
Else
If Cells(i, 2) = Worksheets("Data").Cells(i, 2) And (Cells(i, 13) = "GELO") Then
'Gelo
Z = Cells(i, 5) + 1
Worksheets("RAW").Cells(i, 5).Value = Z
Else
If Cells(i, 2) = Worksheets("Data").Cells(i, 2) And (Cells(i, 13) = "UEBE") And (Cells(i, 11) = 0) Then
'UEBE
Z = Cells(i, 10) + 1
Worksheets("Data").Cells(i, 9).Value = Z
Else
If Cells(i, 11) = 1 And (Cells(i, 28) = "<1") Then
'1
Z = Cells(i, 10) + 1
Worksheets("Data").Cells(i, 10).Value = Z
Else
If Cells(i, 11) = 1 And (Cells(i, 28) = "6") Then
'6
Z = Cells(i, 10) + 1
Worksheets("Data").Cells(i, 11).Value = Z
Else
If Cells(i, 11) = 1 And (Cells(i, 28) = "9") Then
'9
Z = Cells(i, 10) + 1
Worksheets("Data").Cells(i, 12).Value = Z
Else
If Cells(i, 11) = 1 And (Cells(i, 28) = "10") Then
'10
Z = Cells(i, 10) + 1
Worksheets("Data").Cells(i, 13).Value = Z
Else
If Cells(i, 11) = 1 And (Cells(i, 28) = "15") Then
'15
Z = Cells(i, 10) + 1
Worksheets("Data").Cells(i, 14).Value = Z
Else
If Cells(i, 11) = 1 And (Cells(i, 28) = "30") Then
'30
Z = Cells(i, 10) + 1
Worksheets("Data").Cells(i, 15).Value = Z
Else
If Cells(i, 11) = 1 And (Cells(i, 28) = "50") Then
'50
Z = Cells(i, 10) + 1
Worksheets("Data").Cells(i, 16).Value = Z
Else
If Cells(i, 11) = 1 And (Cells(i, 28) = "60") Then
'60
Z = Cells(i, 10) + 1
Worksheets("Data").Cells(i, 17).Value = Z
Else
If Cells(i, 11) = 1 And (Cells(i, 28) = "70") Then
'70
Z = Cells(i, 10) + 1
Worksheets("Data").Cells(i, 18).Value = Z
Else
If Cells(i, 11) = 1 And (Cells(i, 28) = "80") Then
'80
Z = Cells(i, 10) + 1
Worksheets("Data").Cells(i, 19).Value = Z
Else
If Cells(i, 11) = 1 And (Cells(i, 28) = "90") Then
'90
Z = Cells(i, 10) + 1
Worksheets("Data").Cells(i, 20).Value = Z
Else
If Cells(i, 11) = 1 And (Cells(i, 28) = "97") Then
'97
Z = Cells(i, 10) + 1
Worksheets("Data").Cells(i, 21).Value = Z
Else
If Cells(i, 11) = 1 And (Cells(i, 28) = "100") Then
'100
Z = Cells(i, 10) + 1
Worksheets("Data").Cells(i, 22).Value = Z
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End Sub
答案 0 :(得分:0)
这里有迭代Excell Sheet单元格的示例:
Sub test()
Dim range1 As Range
Dim cell As Range
Set range1 = ActiveWorkbook.Sheets("Your sheet name").Range("A1:A5")
For Each cell In range1
Debug.Print cell.Value
Next cell
End Sub
您可以添加另一个循环来检查不同工作表中的值,而不是Debug.Print
。