需要在ElseIf语句参数

时间:2017-10-25 05:55:12

标签: vba excel-vba excel-2010 excel

我大约一个月前开始学习VBA,但我终于遇到了一个问题,我无法在Stack上找到答案。我正在进行一项大型自动化分析,我可以在我的亚马逊广告系列上投放,告诉我是要提高出价,降低出价还是暂停。由于场景太多,我的If语句有很多"和/或"内置于其中。我现在处于一种我无法调出特定范围或单元格的情况,但需要if语句仅在未知空格数量的值大于静态单元格时才起作用。以下是我对此部分分析的当前代码

Sub FutureAnalysis()

Dim Spend As Variant, Sales As Variant, ACoS As Variant
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row

Spend = ActiveCell(x + 5, 0)
Sales = ActiveCell(x + 6, 0)

For x = 7 To FinalRow
    If (Cells(x, 1).Value = "Sum of CPC Bid" Or Cells(x, 1).Value = "Sum of Bid") Then
        If IsError(Spend) Or IsError(Sales) Then
            ActiveCell(x, 1) = "Whoops"
        ElseIf ActiveCell(x + 5, 0).Value > 1 And ActiveCell(x + 6, 0).Value > 1 Then
            ActiveCell(x, 1).FormulaR1C1 = _
             "=AVERAGE(INDEX(RC2:RC[-1],MATCH(R5C[-1],R7C2:R7C[-1],0)):INDEX(RC2:RC[-1],MATCH(R6C[-1],R7C2:R7C[-1],0)))*R6C"
            ActiveCell(x, 2).FormulaR1C1 = _
             "=AVERAGE(INDEX(RC2:RC[-2],MATCH(R5C[-2],R7C2:R7C[-2],0)):INDEX(RC2:RC[-2],MATCH(R6C[-2],R7C2:R7C[-2],0)))*R6C"
            ActiveCell(x, 3).FormulaR1C1 = _
             "=AVERAGE(INDEX(RC2:RC[-3],MATCH(R5C[-3],R7C2:R7C[-3],0)):INDEX(RC2:RC[-3],MATCH(R6C[-3],R7C2:R7C[-3],0)))*R6C"

        ElseIf ActiveCell(x + 5, 0).Value = 0 And ActiveCell(x + 6, 0).Value = 0 Then
            ActiveCell(x, 1).FormulaR1C1 = _
             "=INDEX(RC2:RC[-1],MATCH(R6C[-1],R7C2:R7C[-1],0))*1.5"
            ActiveCell(x, 2).FormulaR1C1 = _
             "=INDEX(RC2:RC[-1],MATCH(R6C[-2],R7C2:R7C[-1],0))*1.5"
            ActiveCell(x, 3).FormulaR1C1 = _
             "=INDEX(RC2:RC[-1],MATCH(R6C[-3],R7C2:R7C[-1],0))*1.5"

        ElseIf ActiveCell(x + 5, 0).Value > 0.1 And ActiveCell(x + 6, 0).Value = 0 And ActiveCell(x + 5, 0).Value > Cells(5, 6).Value Then
                ActiveCell(x - 1, 1).FormulaR1C1 = _
                 "=AVERAGE(INDEX(R[1]C2:R[1]C[-2],MATCH(R5C[-1],R7C2:R7C[-2],0)):INDEX(R[1],MATCH(R6C[-1],R7C2:R7C[-2],0)))"
                ActiveCell(x, 1).FormulaR1C1 = _
                "=ROUNDUP(((R5C6/R[4]C[-1])/R[2]C[-1])*R[-1]C,2)"
                ActiveCell(x + 1, 1).FormulaR1C1 = _
                 "=(R5C6/R[3]C[-1])/R[1]C[-1]"
                ActiveCell(x + 2, 1).FormulaR1C1 = _
                 "=RC[-1] * R[-1]C * 3"
                ActiveCell(x + 4, 1).FormulaR1C1 = _
                 "=ROUNDUP(RC[-1] * R[-3]C,2)"
                ActiveCell(x + 5, 1).FormulaR1C1 = _
                 "=(R[-1]C * R[-3]C) + INDEX(RC2:RC[-2],MATCH(R6C[-1],R7C2:R7C[-2],0))"
                ActiveCell(x + 6, 1).FormulaR1C1 = _
                 "=IF(R[-4]C + INDEX(R[-4]C2:R[-4]C[-2],MATCH(R6C[-1],R7C2:R7C[-2],0))>=2*R[3]C,((R[-4]C+INDEX(R[-4]C2:R[-4]C[-2],MATCH(R6C[-1],R7C2:R7C[-2],0)))/R[3]C)*R4C4,""PAUSE"")"
                ActiveCell(x + 9, 1).FormulaR1C1 = _
                 "=IF(INDEX(R[-7]C2:R[-7]C[-2],MATCH(R6C[-1],R7C2:R7C[-2],0))>(R5C6/INDEX(R[-5]C2:R[-5]C[-2],MATCH(R6C[-1],R7C2:R7C[-2],0))),(R5C6/R[-5]C)*(INDEX(R[-7]C2:R[-7]C[-2],MATCH(R6C[-1],R7C2:R7C[-2],0))/(R5C6 /INDEX(R[-5]C2:R[-5]C[-2],MATCH(R6C[-1],R7C2:R7C[-2],0)))), R5C6/R[-5]C)"
                ActiveCell(x + 11, 1).FormulaR1C1 = _
                 "=R[-6]C / R[-5]C"

        ElseIf ActiveCell(x + 5, 0).Value > 0.1 And ActiveCell(x + 6, 0).Value = 0 And ActiveCell(x + 5, 0).Value < Cells(5, 6).Value And Cells(5, 6).Value / ActiveCell(x + 4, 0).Value >= 50 Then
                ActiveCell(x - 1, 1).FormulaR1C1 = _
                 "=AVERAGE(INDEX(R[1]C2:R[1]C[-2],MATCH(R5C[-1],R7C2:R7C[-2],0)):INDEX(R[1],MATCH(R6C[-1],R7C2:R7C[-2],0)))"
                ActiveCell(x, 1).FormulaR1C1 = _
                "=ROUNDUP(R[-1]C * 1.1,2)"


        ElseIf ActiveCell(x + 5, 0).Value > 0.1 And ActiveCell(x + 6, 0).Value = 0 And ActiveCell(x + 5, 0).Value < Cells(5, 6).Value And Cells(5, 6).Value / ActiveCell(x + 4, 0).Value < 50 Then
                ActiveCell(x - 1, 1).FormulaR1C1 = _
                 "=AVERAGE(INDEX(R[1]C2:R[1]C[-2],MATCH(R5C[-1],R7C2:R7C[-2],0)):INDEX(R[1],MATCH(R6C[-1],R7C2:R7C[-2],0)))"
                ActiveCell(x, 1).FormulaR1C1 = _
                 "=ROUNDUP((R5C6 / R[4]C[-1])/50 * R[-1]C,2)"


    Else
        ActiveCell(x, 1).Value = "It Doesn't Work"
        ActiveCell(x, 2).Value = "It Doesn't Work"
        ActiveCell(x, 3).Value = "It Doesn't Work"

        End If
    End If

    If Cells(x, 1).Value = "Sum of Real ACoS" And IsNumeric(ActiveCell(x - 4, 1)) Then
        If ActiveCell(x - 5, 0) > 0 Then

        ActiveCell(x, 1).FormulaR1C1 = _
            "=(INDEX(R[-6]C2:R[-6]C[-1],MATCH(R1C,R7C2:R7C[-1],0))+(R[-9]C[-1] * R6C * R6C * R[-7]C[-1]) * 3)/((INDEX(R[-5]C2:R[-5]C[-1],MATCH(R1C,R7C2:R7C[-1],0))/R5C4) +((R[-9]C[-1] * R6C)/R[-2]C[-1]) * R4C4 * 3)"
        ActiveCell(x, 2).FormulaR1C1 = _
            "=(INDEX(R[-6]C2:R[-6]C[-2],MATCH(R1C,R7C2:R7C[-2],0))+(R[-9]C[-2] * R6C * R6C * R[-7]C[-2]) * 3)/((INDEX(R[-5]C2:R[-5]C[-2],MATCH(R1C,R7C2:R7C[-2],0))/R5C4) +((R[-9]C[-2] * R6C)/R[-2]C[-2]) * R4C4 * 3)"
        ActiveCell(x, 3).FormulaR1C1 = _
            "=(INDEX(R[-6]C2:R[-6]C[-3],MATCH(R1C,R7C2:R7C[-3],0))+(R[-9]C[-3] * R6C * R6C * R[-7]C[-3]) * 3)/((INDEX(R[-5]C2:R[-5]C[-3],MATCH(R1C,R7C2:R7C[-3],0))/R5C4) +((R[-9]C[-3] * R6C)/R[-2]C[-3]) * R4C4 * 3)"


        ElseIf ActiveCell(x - 5, 0) = 0 Then

        ActiveCell(x, 1).FormulaR1C1 = _
            "=(INDEX(R[-6]C2:R[-6]C[-1],MATCH(R1C,R7C2:R7C[-1],0))+(R[-9]C[-1] * R6C * R6C * R[-7]C[-1]) * 3)/((INDEX(R[-5]C2:R[-5]C[-1],MATCH(R1C,R7C2:R7C[-1],0))/R5C4) +((R[-9]C[-1] * R6C)/R[-2]C[-1]) * R4C4 * 3)"


        End If
    End If
Next x

 MsgBox "Complete"
End Sub

第三个ElseIf语句是需要修复的语句。这条线说 ActiveCell(x + 5, 0).Value > Cells(5, 6).Value需要使用第1行当前列上的日期来查找索引匹配函数,查看左侧,找到第7行中的日期并拉入比活动单元格低5行的数字然后查看是否& #39; s大于单元格R5C6中的值。

我尝试做什么甚至可能,或者我应该尝试另一种方法来解决我的问题?

0 个答案:

没有答案