break line in VBA

KulsteeN

New Member
Joined
Aug 22, 2017
Messages
3
Hi, i'm VERY new to VBA.

I created a sub to "read" what is on a CELL and then return a value.

But i want to BREAK LINE this IF statements so it's easier to read on the script.

Code:
Range("E2").Select    ActiveCell.FormulaR1C1 = _
        "=IF(ISNUMBER(FIND(""DEPOSITO"",[@COMENTARIO])),""DEPOSITO"",IF(ISNUMBER(FIND(""ABONO"",[@COMENTARIO])),""ABONO"",IF(ISNUMBER(FIND(""CHEQUE"",[@COMENTARIO])),""CHEQUE"",IF(ISNUMBER(FIND(""CARGO"",[@COMENTARIO])),""CARGO"",IF(ISNUMBER(FIND(""IMPUESTO"",[@COMENTARIO])),""CARGO"",IF(ISNUMBER(FIND(""AMORTIZACION"",[@COMENTARIO])),""CARGO"",IF(ISNUMBER(FIND(""INTERES"",[@" & _
        "COMENTARIO])),""CARGO"",IF(ISNUMBER(FIND(""COMISION"",[@COMENTARIO])),""CARGO"",IF(ISNUMBER(FIND(""FONDOS OTRO BANCO"",[@COMENTARIO])),""CARGO"",IF(ISNUMBER(FIND(""TRASPASO DESDE LINEA SOBREGIRO"",[@COMENTARIO])),""ABONO"",IF(ISNUMBER(FIND(""PAGO RECIBIDO PRV"",[@COMENTARIO])),""ABONO"")))))))))))" & _
        ""

I want to BREAKLINE this code for each IF statement i do, how can i do it?
THANKS!!
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi Kulsteen,

You can "break up" lines of code by entering SPACE + UNDERSCORE + Hit enter where you would like to break eg:
Code:
Sub testbreak()
    Dim A As Long


    A = 5
    If A <> 0 Then
        MsgBox "This really long line of code " & A _
        & "followed by some more code"
    End If
End Sub

Only caveat is you cannot do this in the middle of a STRING.

Hope that helps
Caleeco
 
Upvote 0
Hi Kulsteen,

You can "break up" lines of code by entering SPACE + UNDERSCORE + Hit enter where you would like to break eg:
Code:
Sub testbreak()
    Dim A As Long


    A = 5
    If A <> 0 Then
        MsgBox "This really long line of code " & A _
        & "followed by some more code"
    End If
End Sub

Only caveat is you cannot do this in the middle of a STRING.

Hope that helps
Caleeco

Hi, it wasn't working at all.

Someone told me to tryout notepad++ to recreat that breakline and it's working now.

Code:
Sub TIPO_MOV_SANTANDER()'
' VUELVE A APLICAR LA FORMULA EN LA TABLA PARA PODER CATEGORIZAR EL TIPO_MOV
'
    Range("E2").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(ISNUMBER(FIND(""Depósito en Efectivo"",[@COMENTARIO])),""DEPOSITO""," & _
        "IF(ISNUMBER(FIND(""ABONO"",[@COMENTARIO])),""ABONO""," & _
        "IF(ISNUMBER(FIND(""Cheque Canje Recibido Otro Ban"",[@COMENTARIO])),""CHEQUE""," & _
        "IF(ISNUMBER(FIND(""CARGO"",[@COMENTARIO])),""CARGO""," & _
        "IF(ISNUMBER(FIND(""IMPUESTO"",[@COMENTARIO])),""CARGO""," & _
        "IF(ISNUMBER(FIND(""AMORTIZACION"",[@COMENTARIO])),""CARGO""," & _
        "IF(ISNUMBER(FIND(""INTERES"",[@COMENTARIO])),""CARGO""," & _
        "IF(ISNUMBER(FIND(""COMISION"",[@COMENTARIO])),""CARGO""," & _
        "IF(ISNUMBER(FIND(""FONDOS OTRO BANCO"",[@COMENTARIO])),""CARGO""," & _
        "IF(ISNUMBER(FIND(""TRASPASO DESDE LINEA SOBREGIRO"",[@COMENTARIO])),""ABONO""," & _
        "IF(ISNUMBER(FIND(""PAGO RECIBIDO PRV"",[@COMENTARIO])),""ABONO"")))))))))))" & _
        ""
    
    
End Sub
 
Upvote 0
Hi Kulsteen

like i mentioned in my first post SPACE + UNDERSCORE + Hit enter. the "&" is not needed, it was just part of the sample code i posted
Code:
ActiveCell.FormulaR1C1 = _
        "=IF(ISNUMBER(FIND(""Depósito en Efectivo"",[@COMENTARIO])),""DEPOSITO""," _
        "IF(ISNUMBER(FIND(""ABONO"",[@COMENTARIO])),""ABONO""," _
        "IF(ISNUMBER(FIND(""Cheque Canje Recibido Otro Ban"",[@COMENTARIO])),""CHEQUE""," _
        ' and so on....


Cheers
Caleeco
 
Last edited:
Upvote 0
I don't know why, but & was needed to work, sorry since i'm very new.

But before adding ( " & _ ) <-- withouth parentheses, it would throw an error on the second "IF" immediatly.

Thank you very much!

Hi Kulsteen

like i mentioned in my first post SPACE + UNDERSCORE + Hit enter. the "&" is not needed, it was just part of the sample code i posted
Code:
ActiveCell.FormulaR1C1 = _
        "=IF(ISNUMBER(FIND(""Depósito en Efectivo"",[@COMENTARIO])),""DEPOSITO""," _
        "IF(ISNUMBER(FIND(""ABONO"",[@COMENTARIO])),""ABONO""," _
        "IF(ISNUMBER(FIND(""Cheque Canje Recibido Otro Ban"",[@COMENTARIO])),""CHEQUE""," _
        ' and so on....


Cheers
Caleeco
 
Upvote 0

Forum statistics

Threads
1,224,901
Messages
6,181,639
Members
453,059
Latest member
jkevin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top