Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2197|回复: 5

[习题] 【已开贴】Excel 2015VBA初级2班第3课B组作业上交贴

[复制链接]
发表于 2015-11-9 10:09 | 显示全部楼层 |阅读模式
本帖最后由 wp8680 于 2015-11-14 12:42 编辑

作业说明及要求:

1、根据第三课所讲的内容,按课堂中的布置的作业,编写一段自认为精练的代码。
2、纯录制代码不加分!无独特思考内容的代码不加分!抄袭他人代码无新意不加分!粗糙不合理的代码少加分!
3、提交作业请注明论坛ID及学号。如:B01-***;作业可以压缩包方式提交,也可以直接贴代码;
4、代码题要求强制声明变量,代码缩进
5、学习是自愿的,学成也是自已的。
6、我们的目标:超出自我,胜出自我。
7、作业截止时间:下节课开始前吧
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2015-11-9 10:30 | 显示全部楼层
B10:lvxia
  1. Option Explicit
  2. Sub 右下角星号填充()
  3.     Dim i%, j%
  4.     For i = 1 To 7
  5.         For j = 1 To i
  6.             Cells(i, 8 - j) = "*"
  7.         Next
  8.     Next
  9. End Sub
  10. Sub 右上角星号填充()
  11.     Dim i%, j%
  12.     For i = 1 To 7
  13.         For j = 1 To 8 - i
  14.             Cells(i, 8 - j) = "*"
  15.         Next
  16.     Next
  17. End Sub
  18. Sub 右下角数字填充()
  19.     Dim i%, j%
  20.     For i = 1 To 7
  21.         For j = 1 To i
  22.             Cells(i, 8 - j) = i
  23.         Next
  24.     Next
  25. End Sub
  26. Sub 右上角数字填充()
  27.     Dim i%, j%
  28.     For i = 1 To 7
  29.         For j = 1 To 8 - i
  30.             Cells(i, 8 - j) = 8 - j
  31.         Next
  32.     Next
  33. End Sub
复制代码
  1. Option Explicit
  2. Sub 超支提醒()
  3.     Dim inC As Double, outC As Double, i%
  4.     inC = 1000
  5.     i = 2
  6.     Do While outC <= inC Or i > 31
  7.         outC = outC + Cells(i, 2)
  8.         i = i + 1
  9.     Loop
  10.     If i <= 31 Then
  11.         MsgBox "这个月超支了,超支日期是:" & Cells(i - 1, 1)
  12.     Else
  13.        MsgBox "这个月没有超支"
  14.     End If
  15. End Sub
复制代码

评分

参与人数 1 +12 金币 +12 收起 理由
wp8680 + 12 + 12 赞一个!

查看全部评分

回复

使用道具 举报

发表于 2015-11-9 17:10 | 显示全部楼层
B11:hsl215

练习
  1. Sub 作业1()
  2.     Dim irow As Integer, icol As Integer
  3.     Worksheets("练习").Select
  4.     With Range("a29:g35")
  5.         .Interior.ColorIndex = 1
  6.         .Font.ColorIndex = 2
  7.         .HorizontalAlignment = xlCenter
  8.         .VerticalAlignment = xlCenter
  9.     End With
  10.     For irow = 1 To 7
  11.         For icol = 8 - irow To 7
  12. '当irow+icol>=8时才填充,因此列循环时从8-irow开始以减少循环次数
  13.             Cells(irow + 28, icol) = "*"
  14.         Next
  15.     Next
  16. End Sub

  17. Sub 作业2()
  18.     Dim irow As Integer, icol As Integer
  19.     Worksheets("练习").Select
  20.     With Range("i29:o35")
  21.         .Interior.ColorIndex = 1
  22.         .Font.ColorIndex = 2
  23.         .HorizontalAlignment = xlCenter
  24.         .VerticalAlignment = xlCenter
  25.     End With
  26.     For irow = 1 To 7
  27.         For icol = irow To 7
  28. '当irow<icol时才填充,因此列循环时从irow开始以减少循环次数
  29.             Cells(irow + 28, icol + 8) = "*"
  30.         Next
  31.     Next
  32. End Sub

  33. Sub 作业3()
  34.     Dim irow As Integer, icol As Integer
  35.     Worksheets("练习").Select
  36.     With Range("a37:g43")
  37.         .Interior.ColorIndex = 1
  38.         .Font.ColorIndex = 2
  39.         .HorizontalAlignment = xlCenter
  40.         .VerticalAlignment = xlCenter
  41.     End With
  42.     For irow = 1 To 7
  43.         For icol = 8 - irow To 7
  44. '当irow+icol>=8时才填充,因此列循环时从8-irow开始以减少循环次数
  45.             Cells(irow + 36, icol) = irow
  46. '填充行标
  47.         Next
  48.     Next
  49. End Sub

  50. Sub 作业4()
  51.     Dim irow As Integer, icol As Integer
  52.     Worksheets("练习").Select
  53.     With Range("I37:o43")
  54.         .Interior.ColorIndex = 1
  55.         .Font.ColorIndex = 2
  56.         .HorizontalAlignment = xlCenter
  57.         .VerticalAlignment = xlCenter
  58.    End With
  59.     For irow = 1 To 7
  60.         For icol = 1 To irow
  61. '当irow>=icol时才填充,因此列循环时从1到irow以减少循环次数
  62.             Cells(irow + 36, icol + 8) = icol
  63. '填充列标
  64.         Next
  65.     Next
  66. End Sub
复制代码
循环作业
  1. Sub 作业之FOR循环()
  2.     Dim i As Integer, isum As Double
  3.     Dim x As Double
  4.     x = Application.InputBox("请输入生产费", "计算本月生活费是否超支", 1000, , , , , 1)
  5.     For i = 2 To 31
  6.         isum = isum + Cells(i, 2)
  7.         If isum > x Then Exit For
  8.     Next
  9.     If isum < x Then
  10.         MsgBox "这个月没有超支,还剩:" & x - isum & "元", vbOKOnly, "提醒"
  11.     Else
  12.         MsgBox Cells(i, 1) & "超支了:" & isum - x & "元", vbExclamation, "超支了"
  13.     End If
  14. End Sub

  15. Sub 作业之数组FOR循环()
  16.     Dim i As Integer, isum As Double, arr
  17.     Dim x As Double
  18.     arr = Worksheets("循环作业").Range("A1:B31")
  19.     x = Application.InputBox("请输入生产费", "计算本月生活费是否超支", 1000, , , , , 1)
  20.     For i = 2 To UBound(arr)
  21.         isum = isum + arr(i, 2)
  22.         If isum > x Then Exit For
  23.     Next
  24.     If isum < x Then
  25.         MsgBox "这个月没有超支,还剩:" & x - isum & "元", vbOKOnly, "提醒"
  26.     Else
  27.         MsgBox arr(i, 1) & "超支了:" & isum - x & "元", vbExclamation, "超支了"
  28.     End If
  29. End Sub

  30. Sub 作业之ForEach循环()
  31.     Dim i As Integer, isum As Double, rng As Range
  32.     Dim x As Double
  33.     x = Application.InputBox("请输入生产费", "计算本月生活费是否超支", 1000, , , , , 1)
  34.     For Each rng In Range("b2:b31")
  35.         isum = isum + rng
  36.         i = i + 1
  37.         If isum > x Then Exit For
  38.     Next
  39.     If isum < x Then
  40.         MsgBox "这个月没有超支", vbOKOnly, "提醒"
  41.     Else
  42.         MsgBox Cells(i, 1) & "超支了:" & isum - x & "元", vbExclamation, "超支了"
  43.     End If
  44. End Sub

  45. Sub 作业之DoWhile循环()
  46.     Dim i As Integer, isum As Double
  47.     Dim x As Double
  48.     x = Application.InputBox("请输入生产费", "计算本月生活费是否超支", 1000, , , , , 1)
  49.     i = 1
  50.     Do While isum < x And i < 31
  51. '当isum<生产费与i<31时循环,只要一个条件不满足退出循环
  52.         i = i + 1
  53.         isum = isum + Cells(i, 2)
  54.     Loop
  55.     If isum < x Then
  56. '判断isum与生产费的大小
  57.         MsgBox "这个月没有超支", vbOKOnly, "提醒"
  58.     Else
  59.         MsgBox Cells(i, 1) & "超支了:" & isum - x & "元", vbExclamation, "超支了"
  60.     End If
  61. End Sub

  62. Sub 作业之DoUntil循环()
  63.     Dim i As Integer, isum As Double
  64.     Dim x As Double
  65.     x = Application.InputBox("请输入生产费", "计算本月生活费是否超支", 1000, , , , , 1)
  66.     i = 1
  67.     Do Until isum > x Or i > 31
  68. '当isum>生产费或i>31时循环,只要一个条件满足退出循环
  69.         i = i + 1
  70.         isum = isum + Cells(i, 2)
  71.     Loop
  72.     If isum < x Then
  73.         MsgBox "这个月没有超支", vbOKOnly, "提醒"
  74.     Else
  75.         MsgBox Cells(i, 1) & "超支了:" & isum - x & "元", vbExclamation, "超支了"
  76.     End If
  77. End Sub
复制代码

评分

参与人数 1 +16 金币 +16 收起 理由
wp8680 + 16 + 16 赞一个!

查看全部评分

回复

使用道具 举报

发表于 2015-11-10 14:15 | 显示全部楼层
B02:dzj4717642
第一个程序
  1. Sub A1()
  2. Dim i As Long
  3. Dim j As Long
  4. For i = 1 To 7
  5.    For j = 1 To i
  6.    Cells(i, 8 - j) = "*"
  7.    Next j
  8. Next i
  9. End Sub
复制代码
第二个程序
  1. Sub A2()
  2. Dim i As Long
  3. Dim j As Long
  4. For i = 1 To 7
  5.    For j = 1 To i
  6.    Cells(i, 8 - j) = i
  7.    Next j
  8. Next i
  9. End Sub
复制代码
第三个程序
  1. Sub A3()
  2. Dim i As Long
  3. Dim j As Long
  4. For i = 1 To 7
  5.    For j = 1 To i
  6.    Cells(i, j) = j
  7.    Next j
  8. Next i
  9. End Sub
复制代码
第4个程序
  1. Sub A4()
  2. Dim i As Long
  3. Dim j As Long
  4. For i = 1 To 7
  5.     For j = i + 0 To 7
  6.        Cells(i, j) = j
  7.     Next j
  8.   Next i
  9. End Sub
复制代码
回答完毕!

评分

参与人数 1 +8 金币 +8 收起 理由
wp8680 + 8 + 8 第四个程序中For j = i + 0 To 7,这里的加.

查看全部评分

回复

使用道具 举报

发表于 2015-11-10 21:53 | 显示全部楼层
B03:horselyq
  1. Option Explicit

  2. Sub zy1()
  3.     Dim i As Long, j As Long
  4.     For i = 1 To 7
  5.         For j = 8 - i To 7
  6.             Cells(i, j) = "*"
  7.         Next j
  8.     Next i
  9. End Sub

  10. Sub zy2()
  11.     Dim i As Long, j As Long
  12.     For i = 1 To 7
  13.         For j = i To 7
  14.             Cells(i, j) = "*"
  15.         Next j
  16.     Next i
  17. End Sub

  18. Sub zy3()
  19.     Dim i As Long, j As Long
  20.     For i = 1 To 7
  21.         For j = 8 - i To 7
  22.             Cells(i, j) = i
  23.         Next j
  24.     Next i
  25. End Sub

  26. Sub zy4()
  27.     Dim i As Long, j As Long
  28.     For i = 1 To 7
  29.         For j = 1 To i
  30.             Cells(i, j) = i
  31.         Next j
  32.     Next i
  33. End Sub

  34. Sub xiaofei()
  35.     Dim i As Long, sum As Long
  36.     For i = 2 To 31
  37.         sum = sum + Cells(i, 2)
  38.         If sum > 1000 Then
  39.             MsgBox "这个月超支了,超支日期为:" & Cells(i, 1)
  40.             Exit Sub
  41.         End If
  42.     Next i
  43.     MsgBox "这个月没超支"
  44. End Sub
复制代码

评分

参与人数 1 +8 金币 +8 收起 理由
wp8680 + 8 + 8 很给力!

查看全部评分

回复

使用道具 举报

发表于 2015-11-11 12:56 | 显示全部楼层
  1. B04:海底之心交作业,学委辛苦啦。
  2. Option Explicit
  3. Sub 作业1()
  4. Dim i As Integer, j As Integer
  5. For i = 1 To 7
  6.     For j = 1 To 7
  7.         If i + j > 7 Then
  8.             Cells(i, j) = "*"
  9.          End If
  10.     Next
  11. Next
  12. End Sub
  13. Sub 作业2()
  14. Dim i As Integer, j As Integer
  15. For i = 1 To 7
  16.     For j = 7 To 1 Step -1
  17.         If i <= j Then
  18.          Cells(i, j) = "*"
  19.          End If
  20.     Next
  21. Next
  22. End Sub
  23. Sub 作业3()
  24. Dim i As Integer, j As Integer, n As Integer
  25. For i = 1 To 7
  26.     n = i
  27.     For j = 1 To 7
  28.         If i + j > 7 Then
  29.             Cells(i, j) = n
  30.         End If
  31.     Next
  32. Next
  33. End Sub
  34. Sub 作业4()
  35. Dim i As Integer, j As Integer, n As Integer
  36. For i = 1 To 7
  37.     For j = 7 To 1 Step -1
  38.         n = j
  39.         If i <= j Then
  40.             Cells(i, j) = n
  41.         End If
  42.     Next
  43. Next
  44. End Sub
  45. Sub 作业5()
  46. Dim i As Integer, n As Integer
  47. For i = 2 To 32
  48.     n = Cells(i, 2).Value + n
  49.     If n >= 1000 Then
  50.         MsgBox Cells(i, 1).Value
  51.     Exit Sub
  52.     End If
  53. Next
  54. End Sub
复制代码

评分

参与人数 1 +8 金币 +8 收起 理由
wp8680 + 8 + 8 很给力!

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-2 23:34 , Processed in 0.291022 second(s), 17 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表