[英]Copy merged cells from other sheets into one cell in summary sheet
I have a workbook which has a Summary Sheet and updates with new sheets (with changing names, imported from a specified path) upon command. 我有一个工作簿,其中有一个摘要表,并根据命令更新了新表(具有更改的名称,从指定路径导入)。 In the summary sheet, I want to collect specific information present in the other sheets (all of them have the same template filled in with different information).
在摘要表中,我想收集其他表中存在的特定信息(它们都具有填充了不同信息的相同模板)。
For example, I want to copy the merged ranges B3:O3
in Sheet X
, Sheet Y
and Sheet Z
into Cells A2, B2, C2
in Summary Sheet. 例如,我想将工作表
X
,工作表Y
和工作表Z
的合并范围B3:O3
复制到摘要工作表中的单元格A2, B2, C2
中。
Questions: 问题:
A) How do I copy the info? A)如何复制信息?
B) How do I link the command to existing "Refresh Sheets" command which populates the workbook with updated information from a specified folder? B)如何将命令链接到现有的“刷新表”命令,该命令使用来自指定文件夹的更新信息填充工作簿?
Relatively new to VBA, so excuse me if question is basic. 对VBA来说相对较新,如果问题很基本,请原谅。 Thanks!
谢谢!
Assuming B3:O3
is a merged range you take the top left cell from each. 假设
B3:O3
是合并范围,则从每个区域的左上角单元格中选取。 Sub RefreshSheets
represents your existing command and then there is a call within that code to the new sub GetInfo
. Sub RefreshSheets
代表您现有的命令,然后在该代码内调用新的Sub GetInfo
。
Like this 像这样
Option Explicit
Public Sub RefreshSheets()
'Your current refresh code
GetInfo 'call to other sub
End Sub
Public Sub GetInfo()
Dim wb As Workbook
Set wb = ThisWorkbook
With wb.Worksheets("Summary Sheet")
.Range("A2") = wb.Worksheets("X").Range("B3")
.Range("B2") = wb.Worksheets("Y").Range("B3")
.Range("C2") = wb.Worksheets("Z").Range("B3")
End With
End Sub
If working with variable sheet names you could assign by position eg 如果使用可变工作表名称,则可以按位置分配,例如
Sheets(Sheets.Count)
Or use a variable 或使用一个变量
Dim X As String
X = "X"
Sheets(X)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.