VBA表单完成跨多个工作表

我在WKBK 1中devise了一个标准模板,用于对教师进行评分。 WKBK 1有15个不同的工作表,每个老师1个。 在WKBK 2 ,我有一个表格用于保存不同function的分数。 我正在使用macros(或试图)来提取WKBK 2数据并将其转储到WKBK 1 。 当我试图在整个工作表中循环macros时,macros从老师1拉,并分配给老师2-15。

 Sub Scorecard() Dim Current As Worksheet For Each Current In Worksheets Range("TeacherYTD") = "='[Teacher Formula.xlsx]Sheet1'!R3C2" Range("B7:C7").Select Range("TeacherCCO") = "='[TeacherFormula.xlsx]Sheet1'!R3C3" Range("F6").Select Next End Sub 

我正在使用“定义”在工作簿中将一个单元格指向另一个单元格。 我不确定这是否是首选的方式,但对于初学VBA程序员来说,这是最直接的。

有人可以帮我弄清楚如何“下一步”到下一行来收集适当的老师的分数?

尝试下面的东西。 这是粗糙和未经testing ,但希望你会发现它有帮助。

 Option Explicit Sub Test() Dim wb1 As Workbook Dim wb2 As Workbook Dim ws As Worksheet Dim ws2 As Worksheet Dim Teachers As Range Dim Teacher As Range 'Using objects makes it much easier to maintain your code. Set wb1 = Workbooks("WKBK 1") Set wb2 = Workbooks("WKBK 2") Set ws2 = wb2.Sheets("YourTableSheet") '<~~ The sheet that contains your table. Set Teachers = ws2.Range("A2:A17") '<~~List of teachers on your table. 'Loop through your list of teachers. For Each Teacher In Teachers 'I'm assuming your template sheets are named the same as your teachers. 'If they (the sheet names and names in the list) aren't exactly the same, 'this code won't work. Set ws = wb1.Sheets(Teacher) 'This is where you'll transfer the data. See my examples. You can add as many as needed. 'This also assumes that every template sheet is set up the same. ws.Range("TeacherYTD") = ws2.Range("B" & Teacher.Row).Value '<~~ Copies/pastes the table data in column B for that particular teacher into that teacher's template sheet. ws.Range("TeacherCCO") = ws2.Range("C" & Teacher.Row).Value '<~~ Same as above except for column C. 'If you have additional data to transfer, model additional lines after the above two lines. Next Teacher End Sub 

希望有所帮助!