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:

IF(R8=“W”,

IF(L8>0,L8,

IF(ABS(L8)<ABS(V7),L8,

IF(N8+L8<0,L8+Z7,-V7)))

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”

        Else

        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

  Loop

  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 *