2017-04-10 73 views
-1

好吧所以我一直在想出一些東西來運行這個。VBA循環函數基於列表中的值

基本上我需要循環表2中列A的值,對於需要在表1中找到它的每個值,然後根據H列中的標識符(4個變量),爲單元格添加一個計數,如果它符合一個標準,那麼它可能需要檢查K列來知道哪個值。

例如:

開始在第2頁第2行,其具有數「123456789」,其中具有在列B(因此B *找到)號碼「123456789」片1查找行 如果H *有一個值,那麼它需要在表格2的正確列中爲該數字添加一個值到記錄器。如果H * =某個標準,那麼它需要檢查列K中的標準,然後將該值添加到正確的列。 我完全失去了如何設置。 任何幫助將是驚人的,非常感謝

喬恩

代碼現在如下: 子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

在這裏,你有例子遍歷的Excell表的單元格:

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您可以添加另一個循環來檢查不同工作表中的值。

+0

謝謝, 我似乎寫了一個代碼,但我不斷收到錯誤maeesages。 我也無法上傳,因爲它太長了 –

+0

你得到了什麼樣的錯誤? –

+0

錯誤溢出。 上面的代碼盡我所能,但它似乎並沒有工作。 –