webForumDet fria alternativet

If Then else..

.NET

3 svar · 453 visningar · startad av Kalle M

Medlem sedan mars 20041 936 inlägg
Frågan#1

Fått för mig att alla If Then else satser avslutas med End if !?

Varför inte i denna? För att jag inte blandat in Else?
Funkar ju i och för sig :-)

Sub JanuariKalkyl()
    If ActiveCell.Offset(0, 1).FormulaR1C1 _
        = "" Then _
            ActiveCell.Offset(0, 1). _
                FormulaR1C1 = "Januari"
    If ActiveCell.Offset(1, 0).FormulaR1C1 _
        = "" Then _
            ActiveCell.Offset(1, 0). _
                FormulaR1C1 = "Kassa"
    If ActiveCell.Offset(1, 1).FormulaR1C1 _
        = "" Then _
            ActiveCell.Offset(1, 1). _
                FormulaR1C1 = "40000"
    If ActiveCell.Offset(2, 0).FormulaR1C1 _
        = "" Then _
            ActiveCell.Offset(2, 0). _
                FormulaR1C1 = "Hyra"
    If ActiveCell.Offset(2, 1).FormulaR1C1 _
        = "" Then _
            ActiveCell.Offset(2, 1). _
                FormulaR1C1 = "8000"
    If ActiveCell.Offset(3, 0).FormulaR1C1 _
        = "" Then _
            ActiveCell.Offset(3, 0). _
                FormulaR1C1 = "Material"
    If ActiveCell.Offset(3, 1).FormulaR1C1 _
        = "" Then _
            ActiveCell.Offset(3, 1). _
                FormulaR1C1 = "5000"
    If ActiveCell.Offset(4, 0).FormulaR1C1 _
        = "" Then _
            ActiveCell.Offset(4, 0). _
                FormulaR1C1 = "Lön"
    If ActiveCell.Offset(4, 1).FormulaR1C1 _
        = "" Then _
            ActiveCell.Offset(4, 1). _
                FormulaR1C1 = "20000"
    If ActiveCell.Offset(5, 0).FormulaR1C1 _
        = "" Then _
            ActiveCell.Offset(5, 0). _
                FormulaR1C1 = "Resultat"
    If ActiveCell.Offset(5, 1).FormulaR1C1 _
        = "" Then _
            ActiveCell.Offset(5, 1). _
                FormulaR1C1 = _
                "=R[-4]C-R[-3]C-R[-2]C-R[-1]C"
End Sub
Medlem sedan maj 200010 687 inlägg
#2

För att du kör if satserna på samma rad (med _).

Medlem sedan juni 200032 967 inlägg
#3

Här har du alla if-satser på en rad var (faktiskt, eftersom du valt att bryta dem med _). Hade de varit uppdelade på annat sätt hade du varit tvungen att ha ett end if för varje if-sats, eller ett enda end if sist, om alla dina if skrivits om till elseif.

Hajen sie? :)

Medlem sedan mars 20041 936 inlägg
#4

Ok tack! :-)

252 ms totalt · 4 externa anrop · v20260731065814-full.2d97a731
121 ms — deklarationer (db)
0 ms — hämta statistik (cache)
128 ms — hämta tråd, inlägg och bilagor (db)
119 ms — ändringar (db)