我有一个问题,我想在我的主工作簿上应用来自不同工作表的值的公式。问题是使用的工作簿是每月,名称更改。我正在考虑将第一张纸重命名为“Sheet1”,并通常为Sheet 1应用该配方。
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
如果我打开了工作簿,我需要引用一般的“工作表1”,仅基于它来减去和计算值。
方法1:
您可以通过查找和替换快速完成:
按Ctrl + F,转到替换选项卡。在“查找”字段中,您可以放置“Sheet1”,然后在“替换”字段中键入要引用的新工作表的名称。
注:您必须打开“选项”菜单,然后在“查找范围”下拉菜单中选择“公式”。
方法2:
您可以使用INDIRECT功能。更多信息:https://exceljet.net/formula/dynamic-worksheet-reference