|
楼主 |
发表于 2009-10-3 10:58
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Excel中逻辑与算符演算程序(代码提示)
假设你在考试,以下这份考卷,你会做吗?
'撰写:宏FANS
'QQ:1158268815
'日期:2009-10-3 10:49:07
001:Sub 逻辑与算符()
'变量定义区变量定义区变量定义区变量定义区
002:Dim i, J As Integer
003:Dim a, b As Boolean
004:Dim xlname As String
005:Dim wb As Workbook
'变量定义区变量定义区变量定义区变量定义区
006:With Sheets("参考")
007: If .[B3] = "" Or .[b4] = "" Then
008: MsgBox "请先输入姓名和学号"
009: Exit Sub
010: End If
011: xlsname = "\St" & .[B3] & .[b4] & ".xls"
012: If .[a1] = 1 Then
013: Set wb = Workbooks(Right(xlname, Len(xlsname) - 1))
014: Else
015: Set wb = ThisWorkbook
016: End If
017:End With
018:With wb.Sheets("答题")
019: .Select
020: .Cells.Clear
021: .[a1].Resize(8) = Application.Transpose(Array("A", "B", "Not A", "A And B", "A Or B ", "A Xor B", "A Eqv B", "A Imp B"))
022: For i = 0 To 1
'以下为1答题区答题区答题区答题区答题区答题区答题区答题区区答题区答题区答题区答题区答题区答题区
'在此给A赋值
'以上为1答题区答题区答题区答题区答题区答题区答题区答题区区答题区答题区答题区答题区答题区答题区
023: For J = 0 To 1
'以下为2答题区答题区答题区答题区答题区答题区答题区答题区区答题区答题区答题区答题区答题区答题区
'在此给B赋值
'以上为2答题区答题区答题区答题区答题区答题区答题区答题区区答题区答题区答题区答题区答题区答题区
024: .[B1].Offset(, i * 2 + J) = a
025: .[B2].Offset(, i * 2 + J) = b
026: .[B3].Offset(, i * 2 + J) = Not a
027: .[b4].Offset(, i * 2 + J) = a And b
028: .[b5].Offset(, i * 2 + J) = a Or b
029: .[b6].Offset(, i * 2 + J) = a Xor b
030: .[b7].Offset(, i * 2 + J) = a Eqv b
031: .[b8].Offset(, i * 2 + J) = a Imp b
032: Next J
033: Next i
034:End With
'保存
035:With wb
036: .Save
037: If Not MsgBox("你确定要提交吗?", vbYesNo, "请答对后再提交,谢谢!") = vbYes Then Exit Sub
038: .SaveAs .Path & xlsname
039: Application.Quit
040:End With
041:End Sub
[ 本帖最后由 zhaozyuan 于 2009-10-3 11:04 编辑 ] |
|