VBA Editor.. Long line / Line too long

Thebatfink

Active Member
Joined
Apr 8, 2007
Messages
410
Hi,

Its probably really simple but I'm scratching my head. I am programically inserting formulas into workbooks, and the formula for this range of cells is quite long. It spills over a line in the VBA editor but for some reason I don't seem to be able to use the usual underscore to continue on the next line?!

For example

Code:
sht.Range("AE" & rnumber & "").Formula = "=IF(OR($I" & rnumber & "="""",$AD" & rnumber & "=""""),"""",IF($I" & rnumber & "=""BLAHBLAHBLAHBLAH"",""BLAHBLAHBLAH"",IF(LEFT($I" & rnumber & ",2)=""BLAH"",""BLAHBLAH"",IF($I" & rnumber & "-$AD" & rnumber & "<=-1,""Yes"",""No"".......

its obviously longer than that but if I put for example the underscore in and some quotes

Code:
sht.Range("AE" & rnumber & "").Formula = "=IF(OR($I" & rnumber & "="""",$AD" & rnumber & "=""""),"""",IF($I" & rnumber & "=""BLAHBLAHBLAHBLAH"",""BLAHBLAHBLAH"",IF(LEFT($I" & rnumber & ",2)" _
"=""BLAH"",""BLAHBLAH"",IF($I" & rnumber & "-$AD" & rnumber & "<=-1,""Yes"",""No"".......

it doesn't like it at all. I'd appreciate it if someone can kick me in the right direction!

Thanks!
Batfink
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Please can anyone help me in creating a VB code for the below. It should be pasted in Cell "MH1" when I run the macro

IF(CONCATENATE(LI1,MK1)="RRUS-11LTE 700",LEFT(B1,2)&"L0"&RIGHT(B1,4)&"_7"&E1&"_1",IF(CONCATENATE(LI1,MK1)="RRUS-E2LTE 700",LEFT(B1,2)&"L0"&RIGHT(B1,4)&"_7"&E1&"_2_E",IF(CONCATENATE(LI1,MK1)="B14 4478LTE 700",LEFT(B1,2)&"L0"&RIGHT(B1,4)&"_7"&E1&"_3_F",IF(CONCATENATE(LK1,MK1)="RRUS-11LTE 850",LEFT(B1,2)&"L0"&RIGHT(B1,4)&"_8"&E1&"_1",IF(CONCATENATE(LK1,MK1)="RRUS-12LTE 850",LEFT(B1,2)&"L0"&RIGHT(B1,4)&"_8"&E1&"_1",IF(CONCATENATE(LM1,MK1)="RRUS-11LTE 1900",LEFT(B1,2)&"L0"&RIGHT(B1,4)&"_9"&E1&"_1",IF(CONCATENATE(LM1,MK1)="RRUS-12LTE 1900",LEFT(B1,2)&"L0"&RIGHT(B1,4)&"_9"&E1&"_1",IF(CONCATENATE(LM1,MK1)="RRUS-32 B2LTE 1900",LEFT(B1,2)&"L0"&RIGHT(B1,4)&"_9"&E1&"_1",IF(CONCATENATE(LO1,MK1)="RRUS-11LTE AWS",LEFT(B1,2)&"L0"&RIGHT(B1,4)&"_2"&E1&"_1",IF(CONCATENATE(LO1,MK1)="RRUS-12LTE AWS",LEFT(B1,2)&"L0"&RIGHT(B1,4)&"_2"&E1&"_1",IF(CONCATENATE(LO1,MK1)="RRUS-32 B66LTE AWS",LEFT(B1,2)&"L0"&RIGHT(B1,4)&"_2"&E1&"_1",IF(CONCATENATE(LQ1,MK1)="RRUS-32LTE WCS",LEFT(B1,2)&"L0"&RIGHT(B1,4)&"_3"&E1&"_1"))))))))))))
 
Upvote 0
Generally it would be Range("MH1")="somestring" *but* strings containing doublequotes need the doublequotes to be doubled up, so maybe:-

Code:
Range("MH1")="=IF(CONCATENATE(LI1,MK1)=""RRUS-11LTE 700"",LEFT(B1,2)&""L0""&RIGHT(B1,4)&""_7""&E1&""_1"",IF(CONCATENATE(LI1,MK1)=""RRUS-E2LTE 700"",LEFT(B1,2)&""L0""&RIGHT(B1,4)&""_7""&E1&""_2_E"",IF(CONCATENATE(LI1,MK1)=""B14 4478LTE 700"",LEFT(B1,2)&""L0""&RIGHT(B1,4)&""_7""&E1&""_3_F"",IF(CONCATENATE(LK1,MK1)=""RRUS-11LTE 850"",LEFT(B1,2)&""L0""&RIGHT(B1,4)&""_8""&E1&""_1"",IF(CONCATENATE(LK1,MK1)=""RRUS-12LTE 850"",LEFT(B1,2)&""L0""&RIGHT(B1,4)&""_8""&E1&""_1"",IF(CONCATENATE(LM1,MK1)=""RRUS-11LTE 1900"",LEFT(B1,2)&""L0""&RIGHT(B1,4)&""_9""&E1&""_1"",IF(CONCATENATE(LM1,MK1)=""RRUS-12LTE 1900"",LEFT(B1,2)&""L0""&RIGHT(B1,4)&""_9""&E1&""_1"",IF(CONCATENATE(LM1,MK1)=""RRUS-32 B2LTE 1900"",LEFT(B1,2)&""L0""&RIGHT(B1,4)&""_9""&E1&""_1"",IF(CONCATENATE(LO1,MK1)=""RRUS-11LTE AWS"",LEFT(B1,2)&""L0""&RIGHT(B1,4)&""_2""&E1&""_1"",IF(CONCATENATE(LO1,MK1)=""RRUS-12LTE AWS"",LEFT(B1,2)&""L0""&RIGHT(B1,4)&""_2""&E1&""_1"",IF(CONCATENATE(LO1,MK1)=""RRUS-32 B66LTE AWS"",LEFT(B1,2)&""L0""&RIGHT(B1,4)&""_2""&E1&""_1"",IF(CONCATENATE(LQ1,MK1)=""RRUS-32LTE WCS"",LEFT(B1,2)&""L0""&RIGHT(B1,4)&""_3""&E1&""_1""))))))))))))"
 
Upvote 0
By the way, you'll probably received more responses if you post a new question in a brand new thread, because that way people will see there are zero replies and they're more likely to look at it rather than a six-year-old thread which has just received one new reply.

If you see what I mean...
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,508
Members
452,918
Latest member
Davion615

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