使用VBA将Round功能插入当前单元格 [英] Insert Round function into current cell using VBA
问题描述
例如,如果单元格A1已经具有,那么我将尝试使Round函数更容易地插入到已经有公式的多个单元格中。公式 = b1 + b2
,使用这个宏后,我想让单元格内容读取 = Round(b1 + b2,)
。每个单元格中的公式不一样,所以 b1 + b2
部分必须是任何东西。
所有我可以得到的是:
Sub Round()
Activecell.FormulaR1C1 = = ROUND(b1 + b2,)
End Sub
所以我真的看以某种方式在所选单元格中获取公式,然后使用VBA编辑这些内容。我不能在任何地方找到答案。
这个怎么样?
Sub applyRound(R As Range)
如果Len(R.Formula)> 0然后
如果Left(R.Formula,1)==then
R.Formula == round(& Right(R.Formula,Len(R.Formula) - 1) &,1)
End If
End If
End Sub
I'm trying to make it easier to insert the Round function into a number of cells that already have formulas in them.
For instance, if cell A1 has the formula =b1+b2
, after the use of this macro, I want the cell contents to read =Round(b1+b2,)
. The formulas in each of the cells are not the same, so the b1+b2
portion has to be anything.
All I can get to is this:
Sub Round()
Activecell.FormulaR1C1 = "=ROUND(b1+b2,)"
End Sub
So I'm really looking for some way to get the formula in a selected cell, and then edit those contents using VBA. I can't find the answer anywhere.
How about this?
Sub applyRound(R As Range)
If Len(R.Formula) > 0 Then
If Left(R.Formula, 1) = "=" Then
R.Formula = "=round(" & Right(R.Formula, Len(R.Formula) - 1) & ",1)"
End If
End If
End Sub
这篇关于使用VBA将Round功能插入当前单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!