Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA宏公式帮助关于在公式栏中不显示公式_Vba_Excel - Fatal编程技术网

Excel VBA宏公式帮助关于在公式栏中不显示公式

Excel VBA宏公式帮助关于在公式栏中不显示公式,vba,excel,Vba,Excel,我想使用if条件公式通过vba宏按钮计算立方体。我写的代码,它的工作是好的,但代码显示在公式栏,也与公式来自vba宏和保持他们的工作,我希望这个公式不应该显示在公式栏和计算应该只通过宏按钮时,我按下它。这是我的密码。谢谢 Sub CalCubMeter() Worksheets("sheet1").Range("d3:d21").Formula = "=if(c3=C3,PRODUCT($c3^3),""-"")" End Sub 大致如下: Public Sub CubeColumnC

我想使用if条件公式通过vba宏按钮计算立方体。我写的代码,它的工作是好的,但代码显示在公式栏,也与公式来自vba宏和保持他们的工作,我希望这个公式不应该显示在公式栏和计算应该只通过宏按钮时,我按下它。这是我的密码。谢谢

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)将多维数据集值更改为sourceArr(i)^3

任何主体都可以帮助我不将公式写入范围,而是将结果写入范围?如何?请你能写出示例代码吗?为什么要检查C3是否等于C3?即使它是空的,它也会等于它本身?