Split Long Code

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,568
Office Version
  1. 2021
Platform
  1. Windows
I have been trying to set up formula below on 3 line using a _ in between but code changes to red

Code:
 "=IF(ISNUMBER(MATCH(RC[-7],'[BR1 Import Template." & C & ".xlsm]Data Import'!C1,0)),VLOOKUP(RC[-7],'[BR1 Import Template." & C & ".xlsm]Data Import'!C1:C7,7,FALSE),VLOOKUP(RC[-7]+0,'[BR1 Import Template." & C & ".xlsm]Data Import'!C1:C7,7,FALSE))"


It would be appreciated if someone could assist me to have code on 3 lines below each other
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hey, I think you have to use quotes before the list separator _ symbol, as well as an ampersand (&)

Code:
Sub FormHelp()
     Range("A1").Formula = "=IF(ISNUMBER(MATCH(RC[-7],'[BR1 Import Template." & C & ".xlsm]Data Import'!C1,0))," & _
     "VLOOKUP(RC[-7],'[BR1 Import Template." & C & ".xlsm]Data Import'!C1:C7,7,FALSE)," & _
     "VLOOKUP(RC[-7]+0,'[BR1 Import Template." & C & ".xlsm]Data Import'!C1:C7,7,FALSE))"
End Sub

Does this work?

EDIT: Take out the Range("A1").Formula part to suit your situation - I used it as a template for testing purposes.
 
Last edited:
Upvote 0
thanks for the help. it works perfectly
 
Upvote 0
You can use variables


Code:
Sub test4()
    Dim wB As String
    wB = "BR1 Import Template." & c & ".xlsm"
    Range("A1").Formula = "=IF(ISNUMBER(MATCH(RC[-7],'[" & wB & "]Data Import'!C1,0))," & _
     "VLOOKUP(RC[-7],'[" & wB & "]Data Import'!C1:C7,7,FALSE)," & _
     "VLOOKUP(RC[-7]+0,'[" & wB & "]Data Import'!C1:C7,7,FALSE))"
End Sub

Or

Code:
Sub test5()
    Dim wB As String, sH As String
    wB = "BR1 Import Template." & c & ".xlsm"
    sH = "Data Import"
    Range("A1").Formula = "=IF(ISNUMBER(MATCH(RC[-7],'[" & wB & "]" & sH & "'!C1,0))," & _
     "VLOOKUP(RC[-7],'[" & wB & "]" & sH & "'!C1:C7,7,FALSE)," & _
     "VLOOKUP(RC[-7]+0,'[" & wB & "]" & sH & "'!C1:C7,7,FALSE))"
End Sub
 
Upvote 0
thanks for your code. Much appreciated
 
Upvote 0

Forum statistics

Threads
1,215,741
Messages
6,126,599
Members
449,320
Latest member
Antonino90

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