# 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

By: Famos

### 10 thoughts on “Excel VBA Question: If, elseIf, esle Statement”

1. ig

Today, I went to the beach front with my children.
I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She
placed the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear.

She never wants to go back! LoL I know this is entirely off topic
but I had to tell someone!

2. Tish Hallczuk

Hiya, I am really glad I’ve found this info. Nowadays bloggers publish only about gossips and internet and this is really frustrating. A good site with exciting content, this is what I need. Thank you for keeping this web site, I’ll be visiting it. Do you do newsletters? Cant find it.

3. HectorMow

[url=http://it.detoxyn.org/dieta-disintossicante-con-mele/]dieta disintossicante con mele[/url]

Great website! It looks extremely professional! Sustain the good work!

4. HectorMow

[url=http://dearjoy.fr/potencialex-prix/]Potencialex prix[/url]

You’ve terrific thing on this website.

5. Brooks

Hola! I’ve been following your weblog for a while now and finally got the bravery to go ahead and give you a shout out from Houston Texas! Just wanted to say keep up the fantastic job!