我的RngTo和RngFrom变量都是单个单元格范围。我正在尝试检查RngFrom变量范围中是否包含公式。我已经看到了有关Excel中内置函数IsFormula()的大量信息,但是不知道我是否在这里正确使用了它。任何帮助或技巧将不胜感激。 Other WB是另一本工作簿,而WS是我正在内部查看的指定工作表。如果单元格有一个公式,我想将公式复制并粘贴到上面,如果没有,我将只取这些值。
Sub ImportRange(OtherWB As String, WS As String, RngTo As String, Optional RngFrom As String)
If RngFrom = "" Then
RngFrom = RngTo
End If
If(StrComp((WorksheetFunction.IsFormula(Workbooks(OtherWB).Worksheets(WS).Range(RngFrom)),"FALSE")=0)Then
ActiveWorkbook.Worksheets(WS).Range(RngTo).Value =
Workbooks(OtherWB).Worksheets(WS).Range(RngFrom).Value
ElseIf(StrComp((WorksheetFunction.IsFormula(Workbooks(OtherWB).Worksheets(WS).Range(RngFrom)),"TRUE")=0)Then
Workbooks(OtherWB).Worksheets(WS).Range(RngFrom).Copy
ActiveWorkbook.Worksheets(WS).Range(RngTo).PasteSpecial xlPasteFormulas
End If
End Sub