wps表格用宏代码计算出现#NAME?顺便帮我看一下代码哪里错了

wps表格用宏代码计算出现#NAME?提示说计算错误:引用了无效的名称
我写的代码如下帮我看一下哪里错了
Sub Macro1()
'
' Macro1 Macro
'
'

'
Columns("A:A").Select
Selection.Delete Shift:=xlShiftToLeft
Columns("C:F").Select
Selection.Delete Shift:=xlShiftToLeft
Cells.Select
Cells.ColumnWidth = 20
Cells.RowHeight = 28.5
Range("D1").Select
Selection.FormulaR1C1 = "佣金"
Range("D2").Select
Selection.FormulaR1C1 = "5"
Rows("1:1").Select
Selection.Insert Shift:=xlShiftDown
Range("E2").Select
Selection.FormulaR1C1 = "合计本金"
Range("E4").Select
Selection.FormulaR1C1 = "佣金"
Range("E3").Select
Selection.FormulaR1C1 = "=SUM(B3:B10000)"
Range("E5").Select
Selection.FormulaR1C1 = "=SUM(D3:D10000)"
Range("E6").Select
Selection.FormulaR1C1 = "合计"
Range("E7").Select
Selection.FormulaR1C1 = "=E3+E5"
Columns("A:F").Select
Selection.HorizontalAlignment = xlHAlignCenter
With Selection.Borders(xlEdgeLeft)
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection.Borders(xlEdgeTop)
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection.Borders(xlEdgeBottom)
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection.Borders(xlEdgeRight)
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection.Borders(xlInsideVertical)
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection.Borders(xlInsideHorizontal)
.Weight = xlThin
.LineStyle = xlContinuous
End With
Selection.Borders(xlEdgeLeft).ColorIndex = xlColorIndexAutomatic
Selection.Borders(xlEdgeTop).ColorIndex = xlColorIndexAutomatic
Selection.Borders(xlEdgeBottom).ColorIndex = xlColorIndexAutomatic
Selection.Borders(xlEdgeRight).ColorIndex = xlColorIndexAutomatic
Selection.Borders(xlInsideVertical).ColorIndex = xlColorIndexAutomatic
Selection.Borders(xlInsideHorizontal).ColorIndex = xlColorIndexAutomatic
Range("E1:E10").Select
With Selection.Font
.Color = 255
.TintAndShade = 0
End With
Selection.Font.Bold = True
Selection.Font.Size = 14
End Sub

你拷贝下面 代码试一下吧。“FormulaR1C1”属性用错了,改成“Formula ”就可以。
--------------------------------------------------------------
Sub Macro1()'
' Macro1 Macro'
Columns("A:A").Select
Selection.Delete Shift:=xlShiftToLeft
Columns("C:F").Select
Selection.Delete Shift:=xlShiftToLeft
Cells.Select
Cells.ColumnWidth = 20
Cells.RowHeight = 28.5
Range("D1").Select
Selection.FormulaR1C1 = "佣金"
Range("D2").Select
Selection.FormulaR1C1 = "5"
Rows("1:1").Select
Selection.Insert Shift:=xlShiftDown
Range("E2").Select
Selection.FormulaR1C1 = "合计本金"
Range("E4").Select
Selection.FormulaR1C1 = "佣金"
Range("E3").Select
Selection.Formula = "=SUM(B3:B10000)"
Range("E5").Select
Selection.Formula = "=SUM(D3:D10000)"
Range("E6").Select
Selection.FormulaR1C1 = "合计"
Range("E7").Select
Selection.Formula = "=E3+E5"
Columns("A:F").Select
Selection.HorizontalAlignment = xlHAlignCenter
With Selection.Borders(xlEdgeLeft)
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection.Borders(xlEdgeTop)
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection.Borders(xlEdgeBottom)
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection.Borders(xlEdgeRight)
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection.Borders(xlInsideVertical)
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection.Borders(xlInsideHorizontal)
.Weight = xlThin
.LineStyle = xlContinuous
End With
Selection.Borders(xlEdgeLeft).ColorIndex = xlColorIndexAutomatic
Selection.Borders(xlEdgeTop).ColorIndex = xlColorIndexAutomatic
Selection.Borders(xlEdgeBottom).ColorIndex = xlColorIndexAutomatic
Selection.Borders(xlEdgeRight).ColorIndex = xlColorIndexAutomatic
Selection.Borders(xlInsideVertical).ColorIndex = xlColorIndexAutomatic
Selection.Borders(xlInsideHorizontal).ColorIndex = xlColorIndexAutomatic
Range("E1:E10").Select
With Selection.Font
.Color = 255
.TintAndShade = 0
End With
Selection.Font.Bold = True
Selection.Font.Size = 14
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-05-28
看不懂代码,但是知道引用的函数名错误。追问

有没有什么解决方法

追答

有啊,重新录制你要的宏。 或者通过你的表格断点运行代码,看在那个位置引用错了,把它改掉。

你这样和我说,还不如你跟我讲你要做什么,或许我还可以帮你提供一些思路。

追问

因为我每天弄的文档都是差不多的

就是计算这两列的

追答

那...你...为...什...么...要...使...用...宏...来...计...算?

固定的格式金额 sum(b: b) 佣金sum(d:d) 总计E3+ E5 不是可以完成你要的数据?

追问

每天都有两千多分,手动算起来太麻烦