我有一大组多项式(例如:“X ^ 2 + 3 * X + 7”)。它们编译如下: 我的范围的第二个,第三个等列(“多项式”)包含多项式,而第一个列包含X值(以命名范围的形式)。
我设法成功编写了一些在整个范围内切换的代码,并用实际的X值替换任何大写或不大写的“x”。
[@flyInOutX]="foo ? 'true' : 'false'"
上面的代码有效。但是我试图通过实现一个数组来改进/缩短代码(@Scott Craner:感谢您的建议!):
Private Sub Loop_Range()
Dim mrngLoop As Range 'this it the specific range which will be looped through to "activate" all its functions
Dim mrngCell As Range 'this is a cell within mrngLoop
Set mrngLoop = range("polynomials")
For Each mrngCell In mrngLoop.Cells
mstrPolynomial = mrngCell.Value
mstrPolynomial = Replace(mstrPolynomial, "X", "x")
mstrPolynomial = Replace(mstrPolynomial, "x", Cells(mrngCell.Row, Range("polynomials").Column - 1).Value)
mstrPolynomial = Replace(mstrPolynomial, ",", ".")
mstrPolynomial = "=" & mstrPolynomial
mrngCell.Value = strPolynomial
Next mrngCell
End Sub