我正在
每当我尝试运行此语法时出现类型不匹配
错误。基本上我想要做的就是将公式应用于整个使用范围的A列。我应该改变什么,以便按要求执行?
Dim wSheet As Worksheet: Set wSheet = Sheets("Master")
Dim lr As Long: lr = wSheet.Cells(wSheet.Rows.Count, "A").End(xlUp).Row
Dim form
form = "=SUBSTITUTE(TRIM(D2),"-","")"
With w.sheet
.Range("A2:A" & lr).FormulaR1C1 = form
End With
答案 0 :(得分:1)
D2
是xlA1 sytax;不是xlR1C1语法。使用RC[3]
向D2提供关系地址或使用.Formula
和xlA1语法。您还需要在带引号的字符串中加倍引号。
With wSheet
lr = .Cells(.Rows.Count, "D").End(xlUp).Row
form = "=SUBSTITUTE(TRIM(D2),"" - "", TEXT(,))"
.Range("A2:A" & lr).Formula = form
form = "=SUBSTITUTE(TRIM(RC[3]),"" - "", TEXT(,))"
.Range("A2:A" & lr).FormulaR1C1 = form
End With
btw,TEXT(,)
与""
相同。