宏放置""在公式中

时间:2014-09-11 13:57:20

标签: excel excel-vba vlookup vba

我正在尝试创建一个宏来替换vlookup单元格中的公式,以包含if(isna ...参数,replacement = vlookup(a1,b1:c2:,2,false)with = IF(ISNA(VLOOKUP(A1,B1:C2:,2,假)),"",VLOOKUP(A1,B1:C2:,2,假))。

我遇到的问题是让宏放置""组件,因为宏解释""什么都没有(就像它会解释" X"作为X而不是" X")。我尝试将其设置为null和false等,但是在单元格中放置0,这对于文本列表不起作用。有任何想法吗?我的宏如下:

Sub vlookuperror()
Dim Orig_formula As String
Dim new_formula
Dim noequal
dim quote

quote=""
Orig_formula = ActiveCell.Formula
noequal = Mid(Orig_formula, 2)
new_formula = "=if(isna(" & noequal & ")," & quote & "," & noequal & ")"
ActiveCell.Formula = new_formula

End Sub

1 个答案:

答案 0 :(得分:0)

试试这个:

Sub vlookuperror()
Dim Orig_formula As String
Dim new_formula
Dim noequal
dim quote

quote=""""""
Orig_formula = ActiveCell.Formula
noequal = Mid(Orig_formula, 2)
new_formula = "=if(isna(" & noequal & ")," & quote & "," & noequal & ")"
ActiveCell.Formula = new_formula

End Sub

或者您应该能够将两个Chr $(34)连接在一起 - 并替换它 - 请参阅Frank N. Stein在上面的评论中提出的建议。 - a la:quote = Chr $(34)& CHR $(34)