重复用户输入的结果

Repeating the result of a user input

我目前正在使用以下 VBA 代码来提示用户输入处理电子表格需要多少人。

Dim N As Long
    N = Application.InputBox(Prompt:="Enter value", Type:=1)
        If N > Rows.Count Then
            N = Rows.Count
        End If

        For i = 1 To N
            Cells(i + 1, 19) = i
        Next i

它完成了我最初需要的功能,如图所示,但我想根据 A 列中剩余的数据重复计数,直到文档结束。因此计数应从单元格 S20 中的 1 开始。

有什么想法吗?

Screenshot of initial Result

最简单的方法就是遍历所有行,但写出(稍微调整过的)行号模 N

Dim N As Long
Dim lastRow As Long

lastRow = Cells(Rows.Count, "A").End(xlUp).Row

N = Application.InputBox(Prompt:="Enter value", Type:=1)

For i = 2 To lastRow
    Cells(i, 19).Value = ((i - 2) Mod N) + 1
Next i