Excel VBA Question: If, elseIf, esle Statement

Im having a little trouble with a code in excel vba. My goal is convert the following if statement to a VBA macro.

The if Statement:





What I want to do is that If there is a W in column R, I want it to check if the amount in Column L is great that zero, if it true, return the amount in column L. If false check if the absolute value of the amount in column L is less than the absolute value of the amount in column V. If true, return the amount in column L otherwise sum the amount in column N and column L. If the sum is less than zero return the sum of the amount in column L and Z. If it’s false return the amount in column v (make it negative).

My attempt to solve it.

   Private Sub looping()

   Dim rw_cnt As Integer

   Application.ScreenUpdating = False

   Application.Calculation = xlCalculationManual

   rw_cnt = 8

   Do While Sheets(“Personal”).Range(“T” & rw_cnt).Value <> “”


   If Sheets(“Personal”).Range(“T” & rw_cnt).Value = “W” Then


        ‘I am having difficulties on this section.

        Sheets(“Personal”).Range(“V” & rw_cnt).Select

        If “=RC[-8]” > 0 Then

        ActiveCell.FormulaR1C1 = “=RC[-8]”

        ElseIf Abs(“=RC[-8]”) < Abs(“=R[-1]C[2”) Then

        ActiveCell.FormulaR1C1 = “=RC[-8]”

        ElseIf (“=RC[-6]” + “=RC[-8]”) < 0 Then

        ActiveCell.FormulaR1C1 = “=RC[-8]” + “=R[-1]C[6”


        ActiveCell.FormulaR1C1 = “=-R[-1]C[7”

        End If


        Sheets(“Personal”).Range(“Z” & rw_cnt).Select

        ActiveCell.FormulaR1C1 = “=0”

  End If


  rw_cnt = rw_cnt + 1


  MsgBox (“Done!!!”)


  Application.ScreenUpdating = True

  Application.Calculation = xlCalculationAutomatic

  End Sub

Thanks in advance!!

By: Famos

Leave a Reply

Your email address will not be published. Required fields are marked *