简体   繁体   中英

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. Here's the part of the code I'm confused about.

Private 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? It runs fine in the original workbook, but when I copy and paste into my workbook it throws a 424 object required error. 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. Any insight into this would be greatly appreciated. Thanks!

"header" is a named range on sheet1. If yo uare using excel 2010 you can go to the "Formulas" tab and click "Name Manager" to see the named range.

The for loop is setting the array "header" to the first 15 rows in the second column of the range named "header" on sheet1.

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.

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