简体   繁体   English

我们可以通过单击具有公式的单元格来运行vba sub吗?

[英]Can we run vba sub by clicking a cell which has a formula?

Is it possible to run the VBA Sub by clicking a cell which has a formula in it. 是否可以通过单击其中包含公式的单元格来运行VBA Sub。

I know its possible to run on a cell which doesn't have a formula to determine its value. 我知道可以在没有公式确定其值的单元格上运行。

How to go about it? 怎么做呢?

Kindly share your thoughts. 请分享您的想法。

Thanks in advance. 提前致谢。

Just use the selection change event and test the .HasFormula property: 只需使用选择更改事件并测试.HasFormula属性即可:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.Count = 1 And Target.HasFormula Then
        '// your code here
    End If
End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 VBA 上引用具有可变公式的 Excel 单元格 - Referencing an excel cell that has a variable formula on VBA 输入一个公式,显示使用vba单击单元格后在求解器中使用该公式 - enter a formula that shows on clicking in a cell using vba then use it in solver 根据不同工作表中的单元格是否具有公式来在单元格中输入的VBA代码 - VBA code to input in cell depending on if a cell in a different sheet has a formula 通过VBA在Excel单元格中设置包含“文本常量”的单元格公式 - Setting cell formula which includes “text constants” in Excel cell by VBA 每次单元格通过公式更改其值时,如何运行 VBA 代码? - How can I run VBA code each time a cell gets its value changed by a formula? Excel VBA-如果单元格具有公式,则对列进行迭代并自动填充 - Excel VBA - Iterate Columns and Autofill if Cell Has Formula 如何使用VBA查找带有公式的单元格是否具有其中的功能? - How to find if a cell with formula has the function within it using VBA? 是否有公式或 VBA 方法来确定 Excel 中突出显示的单元格? - Is there a formula or VBA method to determine which cell is highlighted in Excel? VBA检查带有公式的单元格是否已被覆盖并用原始公式重新填充单元格 - VBA to check if a cell with formula has been overwritten and refill the cell with original formula Excel VBA代码从单元格公式运行宏 - excel vba code to run a macro from a cell formula
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM