我已经为我正在处理的项目包含了 vba 代码。提示用户输入玩家数量。该代码使用用户回答来设置数组的上限。我遇到的问题是代码允许用户输入数据,但不包括最后一个条目。
我加一的变量 i 通常最终会增加更多。
任何帮助,将不胜感激。
我尝试过使用 Do..Until 循环。
Option Explicit
Option Base 1
Sub players()
Dim playername() As String
Dim i As Long
Dim PlayerCount As Long
PlayerCount = InputBox("How many players are there?", "Player Count", "Enter the number of players")
ReDim playername(PlayerCount)
For i = LBound(playername) To UBound(playername)
playername(i) = InputBox("Enter player name:", "Player Name", "Player Name")
MsgBox playername(i) ' test to see if user input is being read
i = i + 1
Next i
Range("A2") = playername(i) 'attempting to add first user name in this cell
Range("A2").Offset(0, 1).Select ' offset cell for other entries
ActiveCell = playername(i)