您的位置首页生活百科

excel表格抽奖如何做

excel表格抽奖如何做

的有关信息介绍如下:

excel表格抽奖如何做

01打开excel,并点击excel的最左上角的图标,找到“Excel 选项”。02找到“常用”点击,然后在右侧找到“在功能区显示‘开发工具’选项卡”复选框打钩,按确定。03点击开发工具,调出开发控件04利用调出的开发控件,2个Label,2个TextBox,1个按钮。结合Excel知识,制作如下界面。05可以在视图中找到宏,也可以在开发工具中找到宏。然后打开宏编辑。06添加VBA代码:Option Base 1Dim t1 As Long '范围1Dim t2 As Long '范围2Dim czh As Integer '抽奖号码Dim num As IntegerSub auto_open()Application.OnKey "{ENTER}", "cj"Application.OnKey "~", "cj"End SubPublic Function tj(lb) As IntegerDim k As Integerk = 2DoSet myR = Sheets(lb).Cells(k, 1)If Trim(myR.Value) = "" Then '出现空记录Exit DoEnd Ifk = k + 1Loop Until Falsetj = k - 1End FunctionPublic Function csf()num = tj("temp")With Worksheets("temp")t1 = .Cells(num, 3).Valuet2 = .Cells(num, 4).ValueEnd WithWorksheets("抽奖程序").TextBox1.Text = t1Worksheets("抽奖程序").TextBox2.Text = t2End FunctionPublic Function cj()num = tj("temp")Call csfCall cjszEnd FunctionPublic Function cjsz()Dim r(10)For i = 1 To 10xh = FalseDod = Int((t2 - t1 + 1) * Rnd + t1)j = 0Doj = j + 1If r(j) = d Thenxh = FalseExit DoElsexh = TrueEnd IfLoop Until j >= iLoop Until xh = Truer(i) = dNext iDim b(1 To 10)For i = 1 To 10b(i) = Application.WorksheetFunction.Small(r, i)Worksheets("抽奖程序").Label1.Caption = ""NextFor j = 1 To 10For i = 1 To 2000If i Mod 100 = 0 ThenDoEventsEnd Ifm = Int((t2 - t1 + 1) * Rnd + t1)Worksheets("抽奖程序").Label2.Caption = Format(m, "00000")Next id = b(j)Worksheets("抽奖程序").Label2.Caption = Format(d, "00000")Worksheets("抽奖程序").Label1.Caption = Worksheets("抽奖程序").Label1.Caption & " " & Worksheets("抽奖程序").Label2.CaptionNext jnn = tj("数据统计")With Worksheets("数据统计").Cells(nn + 1, 1).Value = nn.Cells(nn + 1, 2).Value = Date.Cells(nn + 1, 3).Value = Worksheets("抽奖程序").Label1.CaptionEnd WithFor i = 1 To 14j = nn + 2 - iIf j > 1 ThenWith Worksheets("数据统计")a = .Cells(nn + 2 - i, 2).Valuec = .Cells(nn + 2 - i, 3).ValueEnd WithWith Worksheets("抽奖程序").Cells(i + 1, 14).Value = a.Cells(i + 1, 15).Value = cEnd WithElseExit ForEnd IfNext iEnd Function07点击按钮测试,得到随机中奖编号