简体   繁体   中英

Excel/VBA too many line continuations

I have a large array of column headings in excel/vba When I go over 24 lines , it says too many line continuations. I really need the rest of the columns headings because the code has to look for every single column headings I need. Any suggestions?

myHeaders = Array(Array("Account_ID", "Account_ID"), _
Array("Claim_ID", "Claim_ID"), _
Array("Account_Name", "Account_Name"), _
Array("Claim_Type", "Claim_Type"), _
Array("Coverage", "Coverage"), _
Array("Claim_Level", "Claim_Level"), _
Array("Claim_Count", "Claim_Count"), _
Array("File_Date", "File_Date"), _
Array("File_Year", "File_Year"), _
Array("Resolution_Date", "Resolution_Date"), _
Array("Resolution_Year", "Resolution_Year"), _
Array("Claim_Status", "Claim_Status"), _
Array("Indemnity_Paid", "Indemnity_Paid"), _
Array("Disease_Category", "Disease_Category"), _
Array("State_Filed", "State_Filed"), _
Array("First_Exposure_Date", "First_Exposure_Date"), _
Array("Last_Exposure_Date", "Last_Exposure_Date"), _
Array("Claimant_Employee", "Claimant_Employee"), _
Array("Next", "Next"))

Clippy pops up

  • It looks like you need a Scripting.Dictionary . Would you like to reference the Microsoft Scripting Runtime library?

That way you could have it on as many lines as you want, and keep it readable , without any line continuations:

Dim headings As New Scripting.Dictionary
With headings
    .Add "Account_ID", "Account_ID"
    .Add "Claim_ID", "Claim_ID"
    .Add "Account_Name", "Account_Name"
    '...
    '...
    '...
    .Add "Next", "Next"
End With

Then you can iterate the Keys and Values ; note that Keys must be unique, but if your column headings are actual table headers their uniqueness is already enforced by Excel anyway.

That said I'm not sure I understand why you're doing what you're doing. If your code works as intended I suggest you take it over to Code Review for a tune-up. The whole procedure that's consuming this array, I mean. I'm sure there's a much, much better way to do this.

It is because you can only use so many _'s for one line of code.

Try putting 2 per line and you should be good for a little while (depends how big the array gets). May want to consider moving them to a hidden sheet and reading them in in a loop

myHeaders = Array(Array("Account_ID", "Account_ID"), Array("Claim_ID", "Claim_ID"), _
Array("Account_Name", "Account_Name"), Array("Claim_Type", "Claim_Type"), _

etc

I'm not sure on your approach, but the Line Continuations error you are getting is not an issue with the array, but only with the way that VBA is set up.

There is a maximum amount of times that you can use _ at the end of the line for each statement, and you've hit the limit.

To keep on adding to the array, just delete some of the continuations - it won't look as pretty, but will work eg

Array("Claimant_Employee", "Claimant_Employee"), Array("Another", "Another"), Array("And Another", "And Another"), _

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM