[英]Changing part of an Excel formula based on another cell value
I have an excel formula running in cell C4
with the below formula.我在单元格C4
中使用以下公式运行了一个 excel 公式。
It takes info from cell V5
on the tab called 06-01-20
from a workbook called file1.xlsm
located in C:\Excel\
on my computer.它从位于我计算机上C:\Excel\
中名为file1.xlsm
的工作簿中获取名为06-01-20
的选项卡上的单元格V5
的信息。
='C:\Excel\[file1.xlsm]06-01-20'!V5
I want to change the 06-01-20
part of the formula to the value of cell C2
in my workbook (not the file1.xlsm
workbook, the workbook containing the formula above.)我想将公式的06-01-20
部分更改为我的工作簿中单元格C2
的值(不是file1.xlsm
工作簿,包含上述公式的工作簿。)
Any help would be greatly appreciated.任何帮助将不胜感激。
Screenshot(s) refer -屏幕截图参考 -
Setup设置
Assume 'other' workbook (file1.xlsm) has two sheets:假设“其他”工作簿(file1.xlsm)有两张纸:
Formula:公式:
=SUBSTITUTE(SUBSTITUTE(FORMULATEXT(C4),C1,C2),"=","")
1) Indirect formula approach 1) 间接公式法
Only works if other workbook (file1.xlsm) is open....仅在其他工作簿(file1.xlsm)打开时才有效....
=INDIRECT(D4,1)
2) VBA approach 2)VBA方法
works whether other workbook open / closed, but requires interim 'step' (can be combined with first function if no indirect approach desired)无论其他工作簿是否打开/关闭都有效,但需要临时“步骤”(如果不需要间接方法,可以与第一个功能结合使用)
Insert this function:插入这个函数:
="="&D4
VB code to retrieve value from different sheet (06-01-30):从不同工作表中检索值的 VB 代码 (06-01-30):
Range("G5").Value = Range("E4").Value
Notes:笔记:
#REF!
请注意最终屏幕截图中的间接公式(单元格 G4)如何返回#REF!
whilst VB approach (G5) operates just fine - this is because the VB code was run whilst file1.xlsm was closed而 VB 方法 (G5) 运行良好 - 这是因为 VB 代码在 file1.xlsm 关闭时运行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.