[英]A List From Same Cells Across Multiple Sheets In Excel with sheet names
folks. 乡亲 I have a workbook with multiple sheets, over 200. I'm trying to create in excel a summary sheet called “SUMMARY” where listing the name of all sheets in one column and the content of the cell J2 (in each sheet) in another column.
我有一本包含200多个工作表的工作簿。我试图在Excel中创建一个名为“ SUMMARY”的摘要工作表,其中在一个列中列出所有工作表的名称,在另一列中列出单元格J2的内容(在每个工作表中)柱。 I have found this following code that returns a column with the content of the J2 cell of each sheet but not the columns with the name of the sheet so I'm not able to work with that.
我发现下面的代码返回一个包含每个工作表的J2单元格内容的列,但不返回具有工作表名称的列,因此我无法使用它。 Could you give some tips how to implement the code in order to returns both columns?
您能否提供一些技巧以实现代码以返回两列?
Sub MakeSummaryTableOfACellAcrossSheets()
Dim ws As Worksheet
Application.ScreenUpdating = False
Sheets("SUMMARY").Activate
For Each ws In Worksheets
If ws.Name <> "ITEMS FAMILY" Then
ws.Range("J2").Copy
ActiveSheet.Paste Range("A65536").End(xlUp).Offset(1, 0)
End If
Next ws
Application.ScreenUpdating = True
End Sub
This puts the sheet name in column A of SUMMARY and J2 in column B. 这会将工作表名称放在“概要”的A列中,将J2放在B列中。
I assumed you also wanted to exclude SUMMARY from your loop. 我假设您还想从循环中排除“摘要”。
Transferring values directly rather than copying and pasting is rather quicker. 直接传输值比复制和粘贴要快得多。
Use Rows.Count
rather than hard-coding 65336 as Excel now has more than a million rows. 使用
Rows.Count
而不是对65336进行硬编码,因为Excel现在有超过一百万的行。
Sub MakeSummaryTableOfACellAcrossSheets()
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In Worksheets
If ws.Name <> "ITEMS FAMILY" And ws.Name <> "SUMMARY" Then
Sheets("SUMMARY").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = ws.Name
Sheets("SUMMARY").Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Value = ws.Range("J2").Value
End If
Next ws
Application.ScreenUpdating = True
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.