0
我是比較新的編碼,但在VBA之前工作過(很久以前...)Excel宏循環,並追加
當用戶按下按鈕,啓動宏,一個的InputBox,並詢問然後,要求玩家購買彩票的數量,然後從1-24中隨機分配三個數字(按升序顯示,不重複,就像我們的樂透,我還沒有已經能夠編碼這個條件;我會在稍後...)
在初始代碼運行後,它輸入所有數據行2通過票+1的數量,這一切迄今爲止工作;但是,我希望能夠在每次運行宏時追加到當前列表(每次按下按鈕)。我嘗試了幾種不同的方式來做到這一點,但沒有成功。請幫忙。我究竟做錯了什麼?
Sub New_Entry()
Dim strPlayer As String, strTick As Integer, i As Integer, j As Integer
strPlayer = InputBox("Input Player Name")
strTick = InputBox("How many tickets?")
' For i = 2 To strTick + 1 <-- This works for a single loop that does not append to the previous data
' For i = Range(i & Range(i & Rows.Count).End(xlUp).Row + 1) To Range(i & Range(i & Rows.Count).End(xlUp) + strTick) <-- This does not work, at all.
For j = 1 To 4
Cells(i, 1).Value = strPlayer
Cells(i, j).Value = Int((24 - 1 + 1) * Rnd + 1)
Next j
Next i
End Sub
' Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Value = strPlayer
' Range("B" & Range("B" & Rows.Count).End(xlUp).Row + 1).Value = i
' Range("C" & Range("C" & Rows.Count).End(xlUp).Row + 1).Value = j
@JacobHooper ...添加了unique-sorted-numbers部分;) –