我有以下代码
Option Explicit
Public Sub SegmentLengths()
Dim r, k, j, n As Integer
Dim Li(18), Lseg, M, x, x1, x2, xi, span As Double
xi = Range("B3").Value / 100 'incremento coordinata
n = Range("C72").Value 'nb of lateral restraints
span = xi * 100
Lseg = span / n 'typ segment length
r = 1
While Cells(6 + r, 23).Value > 0
r = r + 1
Wend
k = 1
Li(k) = Sheets("UDL").Application.Max(Cells(6 + r, 18).Value, Lseg)
Cells(1 + k, 60).Value = 0
Cells(2 + k, 60).Value = 0.25 * Li(k)
Cells(3 + k, 60).Value = 0.5 * Li(k)
Cells(4 + k, 60).Value = 0.75 * Li(k)
Cells(5 + k, 60).Value = Li(k)
While k * Lseg < Li(1)
k = k + 1
Wend
x1 = k * Lseg
x = x1
While Cells(6 + r, 23).Value <= 0
r = r + 1
Wend
x2 = Cells(6 + r - 1, 18).Value
j = 1
While k * Lseg <= x2
Cells(2 + 5 * j, 60).Value = x
Cells(3 + 5 * j, 60).Value = x + 0.25 * Lseg
Cells(4 + 5 * j, 60).Value = x + 0.5 * Lseg
Cells(5 + 5 * j, 60).Value = x + 0.75 * Lseg
Cells(6 + 5 * j, 60).Value = x + Lseg
j = j + 1
k = k + 1
x = k * Lseg
Wend
If x2 = span Then
MsgBox (1)
'Cells(2 + 5 * j, 60).Value = x
'Cells(3 + 5 * j, 60).Value = x + 0.25 * (span - j * Lseg)
'Cells(4 + 5 * j, 60).Value = x + 0.5 * (span - j * Lseg)
'Cells(5 + 5 * j, 60).Value = x + 0.75 * (span - j * Lseg)
'Cells(6 + 5 * j, 60).Value = x + (span - j * Lseg)
End If
End Sub
问题是最后的IF x2 = span THEN。 我使用MsgBox显示x2和span只是为了仔细检查,它们完全相同。 但是,当我运行代码时,它不会显示1。 我无法理解为什么! 有什么想法?
由于