VBA实例,在word和excel里插入公式

版权声明:一起学习,一起成长,欢迎关注 奔跑的犀牛先生 https://blog.csdn.net/xuemanqianshan/article/details/89325588

用VBA在单元格里插入公式

据说在一个单元格力很难直接插入公式

https://blog.csdn.net/taller_2000/article/details/86685066

 

暂时不知道用处是啥

 


Sub InputFormula()
    Dim strFormula As String
    Dim objChar As Characters
    Dim i As Integer
    strFormula = "C2=A2+B2"
    ActiveCell.FormulaR1C1 = strFormula
    For i = 1 To VBA.Len(strFormula)
        Set objChar = ActiveCell.Characters(Start:=i, Length:=1)
        
        If VBA.IsNumeric(objChar.Text) Then
           objChar.Font.Superscript = True
        End If
    Next i


'    With ActiveCell
'        .FormulaR1C1 = strFormula
'        For i = 1 To VBA.Len(strFormula)
'            Set objChar = .Characters(Start:=i, Length:=1)
'            If VBA.IsNumeric(objChar.Text) Then
'                objChar.Font.Superscript = True
'            Next i
'    End With
End Sub

猜你喜欢

转载自blog.csdn.net/xuemanqianshan/article/details/89325588
今日推荐