0

in the following loop u can see different if, elseif statements that are neccessary to filter on the excel worksheet

for some reason the elseif statement is not working and i don't know excatly why Is it due to wrong syntax, semantic or something else?

Hope someone can help me out find the problem or can come up with a workaround solution

For counter_MA = 7 To 20
        For counter_ReportTasks = 3 To Report_LastRow
             If CapacityPlaning_WS.Cells(counter_MA, 2).Value = Report_WS.Cells(counter_ReportTasks, 2).Value And Report_WS.Cells(counter_ReportTasks, 3).Value = "Development A" Then _
            value_DevA = value_DevA + Report_WS.Cells(counter_ReportTasks, 4).Value
            ElseIf CapacityPlaning_WS.Cells(counter_MA, 2).Value = Report_WS.Cells(counter_ReportTasks, 2).Value And Report_WS.Cells(counter_ReportTasks, 3).Value = "Development T" Then
             value_DevT = value_DevT + Report_WS.Cells(counter_ReportTasks, 4).Value
            ElseIf CapacityPlaning_WS.Cells(counter_MA, 2).Value = Report_WS.Cells(counter_ReportTasks, 2).Value And Report_WS.Cells(counter_ReportTasks, 3).Value = "AMS" Then
             value_AMS = value_AMS + Report_WS.Cells(counter_ReportTasks, 4).Value
             
             End If
       Next counter_ReportTasks
    CapacityPlaning_WS.Cells(counter_MA, 4).Value = value_DevA
    CapacityPlaning_WS.Cells(counter_MA, 5).Value = value_DevT
    CapacityPlaning_WS.Cells(counter_MA, 6).Value = value_AMS
    Set value_DevA = 0
    Set value_DevT = 0
    Set value_AMS = 0
Next counter_MA
  • 3
    What isn't working? Since we don't have your data nor the entire code there's a number of things that could be wrong. But you should probably remove the `_` in the first `Then _` because you want them on separate rows either way. – Christofer Weber Jul 19 '21 at 10:41

1 Answers1

0

Its because you have a statement on the same line after the Then. The structure of an if/elseif/else/end block should be

If <conditions> then

    <statements>

elseif <conditions> then

     <statements>

else

    <statements>

End If

e.g. nothing on the same line as the Then statements

freeflow
  • 4,129
  • 3
  • 10
  • 18