【发布时间】:2018-03-10 21:11:24
【问题描述】:
问题
我想遍历所有工作表并创建一个摘要工作表。我有一个动态列,而一些标题在COLUMN X 上,而一些在COLUMN AG 上。
因此,为了解决这个问题,我决定获取特定的标题名称,而不是选择特定的列。
但是,我似乎无法在代码上取得进展,因为我不知道如何循环所有工作表,获取列然后将其添加到摘要中。
代码
Public Sub forSummary()
Dim ws As Worksheet
Dim lRow As Long
Dim aCell As Range, rng1 As Range
'~~> Set this to the relevant worksheet
Set ws = ThisWorkbook.Sheets("JAN 6")
With ws
'~~> Find the cell which has the name
Set aCell = .Range("A1:BA1").Find("TOTAL OUT")
'~~> If the cell is found
If Not aCell Is Nothing Then
'~~> Get the last row in that column and check if the last row is > 1
lRow = .Range(Split(.Cells(, aCell.Column).Address, "$")(1) & .Rows.Count).End(xlUp).Row
If lRow > 1 Then
'~~> Set your Range
Set rng1 = .Range(aCell.Offset(1), .Cells(lRow, aCell.Column))
'~~> This will give you the address
rng1.Select
End If
End If
End With
End Sub
有什么想法吗?
【问题讨论】:
-
您需要 VBA 吗?至少在 Libreoffice 中,使用 Sheet1、Sheet2 到 Sheet 5,您可以写
=SUM(Sheet2.A1:B1:Sheet5.A1:B1)来总结第 2 到第 5 之间所有工作表中的 A1:B1。另外:刚刚在 Excel 中找到对应的:superuser.com/questions/331252/…