Option Base 1 Private Sub Form_Click() Dim A A = Array(2, 4, 6, 8, 10, 12, 14, 16) k = Val(InputBox("请输入K=")) i = UBound(A) While ((k <> A(i)) And i >= 1) i = i - 1 Wend A(i) = k ReDim Preserve A(UBound(A) + 1) For j = UBound(A) - 1 To i Step -1 A(j + 1) = A(j) Next j Print End Sub
Option Explicit Private Sub Form_Click() Dim A As Variant, k&, i%, j% A = Array(2, 4, 6, 8, 10, 12, 14, 16) k = Val(InputBox("请输入K=")) i = UBound(A) While ((k <> A(i)) And i >= 1) i = i - 1 Wend A(i) = k ReDim Preserve A(UBound(A) + 1) For j = UBound(A) - 1 To i Step -1 A(j + 1) = A(j) Next j Print End Sub 你看这样呢