0
私はVBAスクリプトを使用していますが、最近私は新しいIF文を追加しましたが、今はsumif値をポストしません。 Lauren CompセクションにAQ列の適切な行にそのIFステートメントの合計を移入させようとしています。Excel VBA sumif
Sub CalculateCommission()
Dim Index As Integer 'Row Index
Dim employeeName As String 'A
Dim compPlan As String 'B
Dim baseWage As Double 'AM
Dim commAN As Double 'AN
Dim guarantee As Double 'AO
Dim earningsDue As Double 'AQ
Dim priorPay As Double 'AR from prior pay cycle
Dim priorBase As Integer 'AS from prior pay cycle
Dim newComm As Double 'AU
Dim packBack As Double 'AP
Index = 3
Do While Len(ActiveSheet.Range("B" & Index))
employeeName = UCase(ActiveSheet.Range("A" & Index))
compPlan = UCase(ActiveSheet.Range("B" & Index))
baseWage = ActiveSheet.Range("AM" & Index)
newComm = ActiveSheet.Range("AU" & Index)
earningsDue = ActiveSheet.Range("AQ" & Index)
guarantee = ActiveSheet.Range("AO" & Index)
packBack = ActiveSheet.Range("AP" & Index)
'set to zero if there's an error - based on prior pay cycle
If (IsError(ActiveSheet.Range("AR" & Index)) = False) Then
priorPay = ActiveSheet.Range("AR" & Index)
Else
priorPay = 0
End If
If (IsError(ActiveSheet.Range("AS" & Index)) = False) Then
priorBase = ActiveSheet.Range("AS" & Index)
Else
priorBase = 0
End If
commAN = ActiveSheet.Range("AN" & Index)
'base plus commission,else
If compPlan = "B" Or compPlan = "D" Or compPlan = "E" Or compPlan = "I" Or compPlan = "J" Or compPlan = "L" Then
commAN = earningsDue - baseWage - guarantee - priorBase
Else
commAN = earningsDue - baseWage - guarantee
End If
'Lauren comp
If compPlan = "L" Then
Sumact = Application.WorksheetFunction.SumIf(Worksheets("Calc by loan").Range("C:C"), "Doe, John", Worksheets("Calc by loan").Range("D:D"))
End If
ActiveSheet.Range("AQ" & Index).Value = Sumact
'base plus commission, else
If compPlan = "B" Or compPlan = "D" Or compPlan = "E" Or compPlan = "I" Or compPlan = "J" Then
If baseWage + newComm > baseWage Then
earningsDue = baseWage + newComm + guarantee + priorBase - priorPay + packBack
Else
earningsDue = baseWage + guarantee + packBack
End If
Else
If newComm > baseWage + priorPay Then
earningsDue = newComm - priorPay + guarantee + packBack
Else
earningsDue = baseWage + guarantee + packBack
End If
End If
ActiveSheet.Range("AQ" & Index).Value = earningsDue
Index = Index + 1
Loop
EndSub:
End Sub
わかりません。私はすべてを試しましたが、値を設定することはできません。他の人は、 "L"というラベルが付いた人以外は、計算に問題があります。私は "L"セクションが計算をしているように感じますが、答えをどこに置くべきかは言いません。私は、利益の行に沿って発言する必要があると思う.Due = sumact。それは理にかなっていますか? –
"L"セクションはAQセルに "sumact"を書き込むようにプログラムに指示しますが、セルの下の15行はインデューデューに設定されます。 iは=拳AQを取り除く和行為ラインとの一番下の行を変更するになるだろう: 'IIFのcomplan = "L"、その後 ActiveSheet.Range( "AQ" &インデックス).Valueの= Sumactエルス ActiveSheet .Range( "AQ"&Index).Value = earningsDue end if ' – scott
うわー!それはうまくいった。すべてのベストそれは私にはほとんど意味があります:)ありがとう –