我正在尝试更新一个旧的宏,它需要验证两个条件,而不是一个。
下面是当前代码:
Columns("G:G").Select
TempString = "IF(RC[4]>0,""1,"","""")&IF(RC[7]>0,""2,"","""")&IF(RC[10]>0,""3,"","""")&IF(RC[13]>0,""4,"","""")"
Selection.FormulaR1C1 = "=IF(LEN(" + TempString + ") > 0, LEFT( " + TempString + ", LEN( " + TempString + " ) - 1 ), " + TempString + " )"
Columns("G:G").EntireColumn.AutoFit
Range("G1").Select
ActiveCell.FormulaR1C1 = "Map"
这是我试图使用的代码。我想让它验证两个条件,而不是现在的这个。它应该验证列名,以及右边有四个空格的单元格(如果单元格中有一个大于0的数字,则为真):
Columns("G:G").Select
TempString = "IF(COUNTIFS(R[-1]C[4],"*MAP*", RC[4], ">0"),""1,"","""")&IF(COUNTIFS(R[-1]C[7],"*MAP*", RC[7], ">0"),""1,"","""")"
Selection.FormulaR1C1 = "=IF(LEN(" + TempString + ") > 0, LEFT( " + TempString + ", LEN( " + TempString + " ) - 1 ), " + TempString + " )"
Columns("G:G").EntireColumn.AutoFit
Range("G1").Select
ActiveCell.FormulaR1C1 = "Map"
当我尝试使用更新后的代码时,我得到&;Expected: End of Statement.&;我知道这是因为逗号,但我不知道把它拉到宏中。任何帮助都会很感激。谢谢你。
TempString = "IF(COUNTIFS(R[-1]C[4],""*MAP*"", RC[4], "">0""),""1,"","""")&" & _
"IF(COUNTIFS(R[-1]C[7],""*MAP*"", RC[7], "">0""),""1,"","""")"
With Columns("G:G")
.FormulaR1C1 = Replace("=IF(LEN(<ts>)>0, LEFT(<ts>, LEN(<ts>)-1),<ts>)", _
"<ts>", TempString)
.EntireColumn.AutoFit
End With
Range("G1").Value = "Map"