[英]Is there a way to use the sheet name from a certain cell (which has been populated using that sheet) to populate another cell?
讓我嘗試更加清楚:
本質上,我的目標是要有一個公式,可以將其插入單元格A2(或宏,如果需要)中,該公式將插入單元格B2來自的工作表的名稱。 在這種情況下,它將是Sheet2。 我已經通過宏記錄器進行了一些嘗試,但是我還無法使任何東西按我想要的方式工作。
理想情況下,我可以選擇一個單元格(在這種情況下為A2單元格)並激活一個宏,或輸入一個公式,該公式將使用該單元格右邊的工作表(B2)填充該單元格(A2)來自。
非常感謝您的幫助,對於我應該為此使用什么或如何做的任何指導將不勝感激。
這是一個UDF,它將為簡單的=SheetX!RANGE
公式提取工作表名稱。 如果有多個圖紙參考或根本沒有參考,它也會發出警報。
將此放置在標准模塊中,並在單元格類型=ReturnSheet(B2)
Function ReturnSheet(rng As Range) As String
Dim sFormula As String
sFormula = rng.Formula
If InStr(1, sFormula, "!") = 0 Then
Dim sSheet As String
sSheet = "No sheet precedents found!"
Else
If UBound(Split(sFormula, "!")) = 1 Then
sSheet = Mid(sFormula, 2, InStr(1, sFormula, "!") - 2)
Else
sSheet = "Multiple Sheet precendents!"
End If
End If
ReturnSheet = Replace(sSheet,"'","") 'replace single quote in sheet names that has spaces
End Function
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.