Excel VBAmacros程序公式帮助关于在公式栏中不显示公式

我想用条件公式来通过vbamacrosbutton来计算立方体。 我编写的代码,它的工作是好的,但代码是在公式栏中显示,也使用公式来自vbamacros并保持它们,我希望这个公式不应该显示在公式栏中,计算只能通过macrosbutton时,我按下它。 这是我的代码。 谢谢

Sub CalCubMeter() Worksheets("sheet1").Range("d3:d21").Formula = "=if(c3=C3,PRODUCT($c3^3),""-"")" End Sub 

有些东西是:

 Public Sub CubeColumnC Dim wb as Workbook Dim ws as Worksheet Dim sourceRange as Range Dim sourceArr() Dim i as long Set wb = ThisWorkbook Set ws = wb.Sheets("Sheet1") 'change to as needed Set sourceRange = ws.Range("C3:C21") 'Assign column c values to array sourceArr = Application.Transpose(sourceRange.Value) With ws For i = Lbound(sourceArr) To Ubound(sourceArr) 'Write back out to col D If .Cells(2+i, "C") = vbNullString Then 'if blank .Cells(2+i, "D") = "-" Else .Cells(2+i,"D") = sourceArr(i)^3 'Calc the Cube value End If Next i End With End Sub 

我忽略了你的C3 = C3,因为这总是正确的,按你认为合适的方式修改。

编辑:Application.WorksheetFunction.Power(sourceArr(i),3)更改为源Arr(i)^ 3的立方体值