在excel vba中设置特定范围的自定义数字格式时,input不匹配错误

我在将自定义数字格式设置为工作表中的特定范围时出错。 我已经尝试了许多组合,但无法find确切的解决scheme..我的代码是:

ws1.Range("C2: C" & p).NumberFormat = "_($* #,##0.00_);_($* (#,##0.00);_($* " - "??_);_(@_)" 'Number format accounting 

如何解决这个问题? 在设置自定义编号时要注意什么? 格式?

代替

 ws1.Range("C2: C" & p).NumberFormat = "_($* #,##0.00_);_($* (#,##0.00);_($* " - "??_);_(@_)" 

尝试

 ws1.Range("C2: C" & p).NumberFormat = "_($* #,##0.00_);_($* (#,##0.00);_($* "" - ""??_);_(@_)" 

注意双引号"" -

看到你的意见,我认为你已经这样做了:

A.select请求数字格式的单元格。

B.运行以下代码:

 Public Sub TestMe() Debug.Print Selection.NumberFormat End Sub 

在即时窗口查看结果并从那里使用。

但是 ,代码应该是这样的:

 Public Sub PrintMeUsefulFormat() Dim strFormula As String Dim strParenth As String strParenth = """" strFormula = Selection.NumberFormat strFormula = Replace(strFormula, """", """""") strFormula = strParenth & strFormula & strParenth Debug.Print strFormula End Sub