如果单元格不等于公式,则为VBA Excel

时间:2016-08-01 14:37:31

标签: excel vba excel-vba if-statement

我想检查一个单元格是否是这个公式然后执行第2部分脚本

代码简化

Range("B1:C1").Select
If ActiveSheet.Name = "Sheet1" And ActiveCell <> "=formula1" Then Sheet1Macro

完整代码(长)

Range("B1:C1").Select
If ActiveSheet.Name = "Sheet1" And ActiveCell <> "=IF(OR(IFERROR(SEARCH(""DKB"",RC[-2]),0),IFERROR(SEARCH(""Cox"",RC[-2]),0),IFERROR(SEARCH(""2020"",RC[-2]),0)),RC[-1],"""")" Then Sheet1Macro

我只是询问如何检查单元格是否为公式,因为我插入行并将公式从A2更改为F99:例如F189

1 个答案:

答案 0 :(得分:1)

If ActiveSheet.Name = "Sheet1" And Range("B1").FormulaR1C1 = "=IF(OR(IFERROR(SEARCH(""DKB"",RC[-2]),0),IFERROR(SEARCH(""Cox"",RC[-2]),0),IFERROR(SEARCH(""2020"",RC[-2]),0)),RC[-1],"""")" Then Sheet1Macro