【问题标题】:How to make NON RANDOM this EXCEL VBA如何使这个 EXCEL VBA 非随机
【发布时间】:2015-04-01 06:29:22
【问题描述】:

伙计们。有人可以帮我解决我的 EXCEL VBA 代码。我真的很难让我的 FLASHCARD 从单元格 A1 到最后一个单元格按顺序显示。我有这段代码,但它只生成一个随机单元格或值。我怎样才能让它非随机?我知道通过使用代码 RND,它会随机生成。但是非随机呢?

代码如下:

Private Sub NextCard()
Application.ScreenUpdating = False

Dim finalTermRow As Integer
finalTermRow = Range("a60000").End(xlUp).Row

Dim possibleRow As Integer
Dim foundTerm As Boolean
foundTerm = False
Dim tries As Integer
tries = 0

Do While foundTerm = False And tries < 1000
    possibleRow = Rnd() * (finalTermRow - 2) + 2

    If Cells(possibleRow, 4).Value = "" Then
        If possibleRow <> previousRow Then
            foundTerm = True
        End If
    End If
    tries = tries + 2
Loop

Application.ScreenUpdating = True

If tries < 1000 Then
    currentRow = possibleRow
    BoxQuestion.Text = Cells(currentRow, 1).Value
    BoxDefinition.Text = ""
    AltBox.Text = ""
Else
    MsgBox ("There are no other cards to go to--you've learned everything else!  Congratulations!  To study all your cards again, click reset.")
End If
End Sub

希望你们能帮我解决这个问题。谢谢。

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    替换:

    tries = 0
    Do While foundTerm = False And tries < 1000
      possibleRow = Rnd() * (finalTermRow - 2) + 2
    

    tries = 0
    possibleRow=0
    Do While foundTerm = False And tries < 1000
       possibleRow = possibleRow + 1
    

    【讨论】:

    • 感谢 Gary 的学生。我尝试了代码并且它有效。但是只有2张卡。如果我有更多卡怎么办?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多