问:excel vba 写一个随机抽奖的小程序

答:以下是一个基本的随机抽奖小程序,使用Excel VBA编写。

Sub Random_Prize_Draw()

Dim Participants() As Variant

Dim NumParticipants As Integer

Dim WinnerIndex As Integer

'输入参与者名单

Participants = Range("A2:A11").Value

NumParticipants = UBound(Participants)

'随机生成赢家

WinnerIndex = Int((NumParticipants - 1 + 1) * Rnd + 1)

'输出赢家

Range("C2").Value = Participants(WinnerIndex, 1)

Range("C3").Value = "恭喜" & Participants(WinnerIndex, 1) & "成为本次抽奖的赢家!"

End Sub

该程序假定参与者名单在单元格 A2:A11 中。程序随机选择一个赢家,并在单元格 C2 中输出其名字,同时在单元格 C3 中输出祝贺信息。可以根据需要修改参与者名单所在的单元格。