简体   繁体   English

Excel中具有多个工作表名称的多个工作表中相同单元格的列表

[英]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.

相关问题 将多个文件中的多个工作表附加到 excel 文件中的相同工作表名称 - Appending multiple sheets from multiple files to the same sheet names in the excel files Excel-工作表名称等于单元格(但为工作表命名的单元格都在同一工作表中) - Excel - sheet names equal to cell (but the cells giving name to the sheets are all in the same sheet) 将单元格中的单元格复制到多张Excel - VBA中 - copy cells from one sheet into multiple sheets Excel - VBA Excel VBA:将单元格从多个工作表复制到单个工作表 - Excel VBA: Copy cells from multiple sheets to a single sheet excel从列表中重命名多个工作表名称 - excel rename multiple sheet names from list 使用 VBA 中同一工作表中的单元格值重命名 Excel 中的多个工作表 - Rename Multiple sheets in Excel with cell value from same sheet in VBA 将多张纸中的同一行复制到Excel中的一张纸中 - copy the same row from multiple sheets into one sheet in excel Excel宏:将特定的单元格从多个工作表复制到单独的工作表中的特定单元格 - Excel Macro: Copy specific cells from multiple sheets to specific cells in separate sheet Excel VBA根据列表从多个工作表复制工作表数据 - Excel VBA copy sheet data from multiple sheets based on list 从多个 excel 文件的每个工作表中复制相同的单元格 - Copy the same cells from every sheet of multiple excel files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM