Excel / VBA:用公式查找范围内的常量

我想在excel / vba中设置一个公式,这将允许我在一个单元格中input单元格的范围和输出,不pipe在那个范围内是否有任何常量。 它真的很容易做一个单元格,但我似乎无法得到的范围工作。 有任何想法吗?

谢谢,杰里米

UDF的代码将返回值为True且没有公式的单元格:

 Option Explicit Public Function DetectConstantInRange(rng As Range) As Boolean Dim rngCell As Range Dim blnResult As Boolean 'assume false blnResult = False 'iterate each cell in range For Each rngCell In rng 'cell with value and no formula is constant If Not rngCell.HasFormula And rngCell.Value <> vbEmpty Then blnResult = True 'at least one constant so exit Exit For End If Next rngCell 'return result DetectConstantInRange = blnResult End Function 

从这里开始:

http://www.excel-easy.com/vba/examples/loop-through-defined-range.html

你需要决定你想使用哪个范围的函数,定义它,添加一个循环来遍历范围内的所有单元格并应用你的函数。