Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.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
如何在excelvba中沿整列运行方程_Excel_Vba - Fatal编程技术网

如何在excelvba中沿整列运行方程

如何在excelvba中沿整列运行方程,excel,vba,Excel,Vba,我想运行一个excel vba,它将进入E列,找到值=“capa”后将进入下面的两个单元格,计算该单元格的hex2dec值,在F列中以值“capa”显示该单元格,并继续向下搜索E列。 到目前为止,我已经提供了以下内容,但不起作用: For Each cell In Range("E:E") If cell.Value = "Capa" Then ActiveCell.Offset.FormulaR1C1 = "=HEX2DEC(R[2]C[-1])"

我想运行一个excel vba,它将进入E列,找到值=“capa”后将进入下面的两个单元格,计算该单元格的hex2dec值,在F列中以值“capa”显示该单元格,并继续向下搜索E列。 到目前为止,我已经提供了以下内容,但不起作用:

 For Each cell In Range("E:E")
     If cell.Value = "Capa" Then
           ActiveCell.Offset.FormulaR1C1 = "=HEX2DEC(R[2]C[-1])"
     End If
Next cell

谢谢

像这样的怎么样

这将在E卷中搜索“Capa”,如果找到,将使用E列中“Capa”正下方的值将公式放在F列中

Sub CapaSearch()
    Dim cl As Range

    For Each cl In Range("E:E")
        If cl.Value = "Capa" Then
            cl.Offset(0, 1).Formula = "=HEX2DEC(" & cl.Offset(1, 0) & ")"
        End If
    Next cl
End Sub

您确实希望限制循环,以便不在整个工作表上循环(Excel 2007+中有1000000多行)(
此外,将源数据复制到变量数组也会加快速度

试试这个

Sub Demo()
    Dim dat As Variant
    Dim i As Long
    With ActiveSheet.UsedRange
        dat = .Value
        For i = 1 To UBound(dat, 1)
            If dat(i, 6 - .Column) = "Capa" Then
                .Cells(i, 7 - .Column).FormulaR1C1 = "=HEX2DEC(R[2]C[-1])"
            End If
        Next
    End With
End Sub