Excel / VBA太多的行延续

我在excel / vba中有大量的列标题当我超过24行时,它说太多的行延续。 我真的需要其余的列标题,因为代码必须查找我需要的每一个列标题。 有什么build议么?

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")) 

Clippypopup

  • 看起来你需要一个Scripting.Dictionary 。 你想参考微软脚本运行时库吗?

这样你就可以在任意多行上保留它并且保持可读性 ,不需要任何行延续:

 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 

然后你可以迭代KeysValues ; 请注意, Keys必须是唯一的,但是如果您的列标题是实际的表头,则它们的唯一性已由Excel强制执行。

这就是说我不确定我明白你为什么要做你正在做的事情。 如果您的代码按照预期工作,我build议您将代码复制到代码审查中。 我的意思是整个程序正在消耗这个数组。 我相信有一个更好的方法来做到这一点。

这是因为你只能使用这么多_代表一行代码。

尝试把每行2,你应该是一段时间的好(取决于数组有多大)。 可能要考虑将它们移动到一个隐藏的表单中,并循环读取它们

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

等等

我不确定你的方法,但是你得到的Line Continuations错误不是数组的问题,而只是用VBA的设置方式。

对于每个语句,您可以在行末使用_的最大次数,并且达到了上限。

要继续添加到数组,只需删除一些延续 – 它不会看起来很漂亮,但将工作,例如

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