Please help with vba code!

redplatinum2

New Member
Joined
Feb 7, 2014
Messages
2
Hello,

I am having issues making this line of code work. I used record macro and plugged in the formula I created. It is too long for VBA and I cannot properly continue on the next line. Can someone help me break this formula into multiple lines on VBA?

ActiveCell.FormulaR1C1 = _
"=IF(RC[-1]=""Southwest Airlines (vendor)"",""WN"",IF(RC[-1]=""Avianca"",""AV"",IF(RC[-1]=""Emirates"",""EK"",IF(RC[-1]=""United Airlines"",""UA"",IF(RC[-1]=""American Airlines"",""AA"",IF(RC[-1]=""Air Canada"",""AC"",IF(RC[-1]=""LAN Airlines S.A"",""LA"",IF(RC[-1]=""Alaska Airlines"",""AS"",IF(RC[-1]=""EMIRATES AIRWAYS -A-U-S"",""EK"",IF(RC[-1]=""Crossair AG"",""LX"",IF(RC[-1]=""Delta Air Lines"",""DL"",IF(RC[-1]=""Qatar Airways"",""QR"",IF(RC[-1]=""Frontier Airlines (Vendor)"",""F9"",IF(RC[-1]=""Air India"",""AI"",IF(RC[-1]=""Air France"",""AF"",IF(RC[-1]=""USAir"",""US"",IF(RC[-1]=""Deutsche Lufthansa AG"",""LH"",IF(RC[-1]=""Westates Airlines dba Gray Line Air"",""WS"",IF(RC[-1]=""Jetblue Airways"",""B6"",IF(RC[-1]=""Aeromexico-Aerovias de Mexico S.A. de C."",""AM"",IF(RC[-1]=""Scandinavian Airlines System (SAS)"",""SK"",IF(RC[-1]=""Tam Linhas Aereas S.A."",""JJ"",IF(RC[-1]=""British Airways P.L.C."",""BA"",IF(RC[-1]=""Cathay Pacific Airways Ltd."",""CX"",IF(RC[-1]=""Virgin Atlantic Airways Limited"",""VS"",IF(RC[-1]=""Qantas Airways Limited"",""QF"",IF(RC[-1]=""Jet Airways (India) Private Limited"",""9W"",IF(RC[-1]=""Delta Airlines (Vendor)"",""DL"",IF(RC[-1]=""Aer Lingus P.L.C."",""EI"", IF(RC[-1]=""Alaska Airlines (vendor)"",""AS""))))))))))))))))))))))))))))))"
Range("I2").Select
Selection.AutoFill
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I think you just need to add line breaks like this

Code:
ActiveCell.FormulaR1C1 = _
 "=IF(RC[-1]=""Southwest Airlines (vendor)"",""WN"",IF(RC[-1]=""Avianca"",""AV"",IF(RC[-1]=""Emirates"",""EK"",IF(RC[-1]=""United Airlines"",""UA"",IF(RC[-1]=""American Airlines"",""AA"",IF(RC[-1]=""Air Canada""" _
 & ",""AC"",IF(RC[-1]=""LAN Airlines S.A"",""LA"",IF(RC[-1]=""Alaska Airlines"",""AS"",IF(RC[-1]=""EMIRATES AIRWAYS -A-U-S"",""EK"",IF(RC[-1]=""Crossair AG"",""LX"",IF(RC[-1]=""Delta Air Lines"",""DL"",IF(RC[-1]=""Qatar Airways"",""QR"",IF(RC[-1]=""Frontier Airlines (Vendor)"",""F9"",IF(RC[-1]=""Air India"",""AI"",IF(RC[-1]=""Air France"",""AF"",IF(RC[-1]=""USAir"",""US"",IF(RC[-1]=""Deutsche Lufthansa AG"",""LH"",IF(RC[-1]=""Westates Airlines dba Gray Line Air"",""WS"",IF(RC[-1]=""Jetblue Airways"",""B6"",IF(RC[-1]=""Aeromexico-Aerovias de Mexico S.A. de C."",""AM"",IF(RC[-1]=""Scandinavian Airlines System (SAS)"",""SK"",IF(RC[-1]=""Tam Linhas Aereas S.A."",""JJ"",IF(RC[-1]=""British Airways P.L.C."",""BA"",IF(RC[-1]=""Cathay Pacific Airways Ltd."",""CX"",IF(RC[-1]=""Virgin Atlantic Airways Limited"",""V" _
& "S"",IF(RC[-1]=""Qantas Airways Limited"",""QF"",IF(RC[-1]=""Jet Airways (India) Private Limited"",""9W"",IF(RC[-1]=""Delta Airlines (Vendor)"",""DL"",IF(RC[-1]=""Aer Lingus P.L.C."",""EI"", IF(RC[-1]=""Alaska Airlines (vendor)"",""AS""))))))))))))))))))))))))))))))"
 
Upvote 0

Forum statistics

Threads
1,215,947
Messages
6,127,867
Members
449,410
Latest member
adunn_23

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