根据案例计算值并粘贴到另一张表中

时间:2017-07-26 12:06:14

标签: excel vba excel-vba

我有张" BW"和另一张表"结果"。工作表结果有一个表,其中包含A列中的周数。

我想在表单中查找周数"结果"如果周数与我的工作表中的周数相同" BW"在列" AX"那么,我想算一下" 1"在表格" BW"在专栏" T"和"你"。

但问题是我有两个案例来计算" 1"在T栏和U栏中

  1. AA列不应等于null。
  2. Z栏应该包含" Ontime"。
  3. 如果这两种情况满足,那么我想查看列中T和U以及1的wount计数。

    我试过了代码。但案件并未令人满意。任何领导都会有所帮助。

    Sub results()
    
    Dim i As Integer, j As Integer, cntT As Integer, cntu As Integer, ws As Worksheet
    Set ws = Sheets("Result")
    Sheets("BW").Select
    For i = 2 To WorksheetFunction.CountA(ws.Columns(1))
    cntT = 0
    cntu = 0
    If ws.Range("A" & i) = Val(Format(Now, "ww")) Then Exit For
    Next i
    
    For j = 5 To WorksheetFunction.CountA(Columns(50))
    
    If ws.Range("AA" & i) <> "" And ws.Range("Z" & i) = "PSW Ontime" Then
    ElseIf ws.Range("A" & i) = Range("AX" & j) And Range("T" & j) = 1 Then cntT = cntT + 1
    ElseIf ws.Range("A" & i) = Range("AX" & j) And Range("U" & j) = 1 Then cntu = cntu + 1
    
    Next j
    If cntT <> 0 Then ws.Range("B" & i) = cntT
    If cntu <> 0 Then ws.Range("C" & i) = cntu
    If cntT + cntu <> 0 Then
    ws.Range("D" & i) = cntT + cntu
    ws.Range("E" & i) = cntT / (cntT + cntu)
    ws.Range("F" & i) = cntu / (cntT + cntu)
    End If
    
    ws.Range("E" & i & ":F" & i).NumberFormat = "0%"
    End If
    End Sub
    

    This how my sheet "BW" look like. The first row is the column name reference. I would like to look for the column "aX" and then check for column "AA" and "Z" and then count the number of 1 in column T and U.

    This is the sample of my sheet2, it has an table. so it looks for the weeknumber in my sheet "BW" and if it is 30, then paste the count values in the columns accordingly

    有人可以帮助我,我如何在我的代码中介绍这个案例。

0 个答案:

没有答案