答案 0 :(得分:0)
实现此目标的一种方法如下,它将公式带入一个变量,然后循环遍历以查找所有工作表名称并将其写入第2行(适用时进行更改):
Sub doit()
Dim ws As Worksheet: Set ws = Sheets("Sheet1")
'declare and set the worksheet you are working with
Valu = ws.Cells(1, 1).Formula
'get the formula into a variable
For i = 1 To Len(Valu) 'loop through the variable
pos = InStr(Valu, "!") 'if ! found
If pos > 0 Then
ws.Cells(2, i).Value = Mid(Valu, 2, pos - 2) 'write into row 2 the Sheet name found
Valu = Right(Valu, Len(Valu) - pos - 2)
'replace the original variable to remove the first Sheet name found
End If
Next i
End Sub