我遇到一个问题,我想在我的主工作簿上应用一个公式,其中包含来自不同工作表的值。问题是所使用的工作簿是每月的,名称更改了。我当时正在考虑将第一张工作表重命名为“ Sheet1”,并在第一张工作表中应用该公式。
Function AlreadyOpen(sFname As String) As Boolean
Dim wkb As Workbook
On Error Resume Next
Set wkb = Workbooks(sFname)
AlreadyOpen = Not wkb Is Nothing
Set wkb = Nothing
End Function
Sub ianuarie()
'ianuarie
Dim wb2 As Workbook
Set wb2 = Workbooks.Open("d:\LocalData\pw02353\Desktop\SDA si raport lunar\SDA ianuarie.xlsx")
Dim wb1 As Workbook
If AlreadyOpen("Estimation & Effort Tracking_SCAR_PE-S&P_DVO_2019.xlsx") Then
Else
Set wb1 = Workbooks.Open("d:\LocalData\pw02353\Desktop\SDA si raport lunar\Estimation & Effort Tracking_SCAR_PE-S&P_DVO_2019.xlsx")
End If
Workbooks("Estimation & Effort Tracking_SCAR_PE-S&P_DVO_2019.xlsx").Activate
Range("U2").Select
ActiveCell.FormulaR1C1 = _
"=SUMIF('[SDA ianuarie.xlsx]Sheet1'!C2,RC[-18],'[SDA ianuarie.xlsx]Sheet1'!C6)"
Range("U2").Select
Selection.AutoFill Destination:=Range("U2:U66"), Type:=xlFillDefault
Range("U2:U66").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=-78
Range("U2").Select
Application.CutCopyMode = False
End Sub
Option Explicit
Sub MonthTest() Dim strMonth As String
strMonth = InputBox("Introduceti luna", "Raport lunar", "ianuarie")
If strMonth = "ianuarie" Then
Call ianuarie
MsgBox "Ati selectat raportul pe luna ianuarie" ElseIf strMonth = "februarie" Then
Call februarie
MsgBox "Ati selectat raportul pe luna februarie"....and so on for each month
如果我打开了工作簿,则需要引用通用的“ Sheet 1”,只是要减去并基于该工作簿计算值。
答案 0 :(得分:0)
方法1:
您可以通过查找和替换来快速完成此操作:
按Ctrl + F,转到“替换”选项卡。在“查找”字段中可以输入“ Sheet1”,在“替换”字段中输入要引用的新工作表的名称。
您必须打开“选项”菜单,然后在“查找范围”下拉菜单中选择“公式”。
方法2:
您可以使用INDIRECT功能。更多信息: https://exceljet.net/formula/dynamic-worksheet-reference
答案 1 :(得分:0)