简体   繁体   English

此vba代码是什么意思?

[英]What does this vba code mean?

I'm trying to duplicate some code a former coworker of mine wrote in an excel spread sheet, but I'm a little new to VBA so I'm having trouble parsing it out. 我正在尝试复制我的一位前同事在excel电子表格中编写的一些代码,但是我对VBA还是有点陌生​​,所以很难解析它。 Here's the part of the code I'm confused about. 这是我很困惑的部分代码。

Private Sub cbWriteIES_Click() 私人Sub cbWriteIES_Click()

 Dim Hangle, Vangle As Double Dim header(1 To 15) As String 'ASSIGN HEADER TO VARIABLE For i = 1 To 15 header(i) = Sheet1.[header].Cells(i, 1) & Sheet1.[header].Cells(i, 2) Next i 

Can someone explain to me what's happening in the for loop? 有人可以向我解释一下for循环中发生了什么吗? It runs fine in the original workbook, but when I copy and paste into my workbook it throws a 424 object required error. 它在原始工作簿中可以正常运行,但是当我将其复制并粘贴到工作簿中时,它将引发424对象必需的错误。 It looks to me like he's associated an object with Sheet1 called [header] but I can't seem to find where he did that. 在我看来,他将一个与Sheet1关联的对象称为[header],但我似乎找不到他在哪里进行的操作。 Any insight into this would be greatly appreciated. 任何对此的见解将不胜感激。 Thanks! 谢谢!

"header" is a named range on sheet1. “页眉”是sheet1上的命名范围。 If yo uare using excel 2010 you can go to the "Formulas" tab and click "Name Manager" to see the named range. 如果您使用的是Excel 2010,则可以转到“公式”选项卡,然后单击“名称管理器”以查看命名范围。

The for loop is setting the array "header" to the first 15 rows in the second column of the range named "header" on sheet1. for循环将sheet1上名为“ header”的范围的第二列中的数组“ header”设置为前15行。

The 424 Object Required error is coming up because you do not have a range named "header" on sheet1 in the workbook you copied this to. 由于您将其复制到的工作簿中的sheet1上没有名为“ header”的范围,因此出现424 Object Required错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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