|
B11:hsl215
练习- Sub 作业1()
- Dim irow As Integer, icol As Integer
- Worksheets("练习").Select
- With Range("a29:g35")
- .Interior.ColorIndex = 1
- .Font.ColorIndex = 2
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- For irow = 1 To 7
- For icol = 8 - irow To 7
- '当irow+icol>=8时才填充,因此列循环时从8-irow开始以减少循环次数
- Cells(irow + 28, icol) = "*"
- Next
- Next
- End Sub
- Sub 作业2()
- Dim irow As Integer, icol As Integer
- Worksheets("练习").Select
- With Range("i29:o35")
- .Interior.ColorIndex = 1
- .Font.ColorIndex = 2
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- For irow = 1 To 7
- For icol = irow To 7
- '当irow<icol时才填充,因此列循环时从irow开始以减少循环次数
- Cells(irow + 28, icol + 8) = "*"
- Next
- Next
- End Sub
- Sub 作业3()
- Dim irow As Integer, icol As Integer
- Worksheets("练习").Select
- With Range("a37:g43")
- .Interior.ColorIndex = 1
- .Font.ColorIndex = 2
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- For irow = 1 To 7
- For icol = 8 - irow To 7
- '当irow+icol>=8时才填充,因此列循环时从8-irow开始以减少循环次数
- Cells(irow + 36, icol) = irow
- '填充行标
- Next
- Next
- End Sub
- Sub 作业4()
- Dim irow As Integer, icol As Integer
- Worksheets("练习").Select
- With Range("I37:o43")
- .Interior.ColorIndex = 1
- .Font.ColorIndex = 2
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- For irow = 1 To 7
- For icol = 1 To irow
- '当irow>=icol时才填充,因此列循环时从1到irow以减少循环次数
- Cells(irow + 36, icol + 8) = icol
- '填充列标
- Next
- Next
- End Sub
复制代码 循环作业- Sub 作业之FOR循环()
- Dim i As Integer, isum As Double
- Dim x As Double
- x = Application.InputBox("请输入生产费", "计算本月生活费是否超支", 1000, , , , , 1)
- For i = 2 To 31
- isum = isum + Cells(i, 2)
- If isum > x Then Exit For
- Next
- If isum < x Then
- MsgBox "这个月没有超支,还剩:" & x - isum & "元", vbOKOnly, "提醒"
- Else
- MsgBox Cells(i, 1) & "超支了:" & isum - x & "元", vbExclamation, "超支了"
- End If
- End Sub
- Sub 作业之数组FOR循环()
- Dim i As Integer, isum As Double, arr
- Dim x As Double
- arr = Worksheets("循环作业").Range("A1:B31")
- x = Application.InputBox("请输入生产费", "计算本月生活费是否超支", 1000, , , , , 1)
- For i = 2 To UBound(arr)
- isum = isum + arr(i, 2)
- If isum > x Then Exit For
- Next
- If isum < x Then
- MsgBox "这个月没有超支,还剩:" & x - isum & "元", vbOKOnly, "提醒"
- Else
- MsgBox arr(i, 1) & "超支了:" & isum - x & "元", vbExclamation, "超支了"
- End If
- End Sub
- Sub 作业之ForEach循环()
- Dim i As Integer, isum As Double, rng As Range
- Dim x As Double
- x = Application.InputBox("请输入生产费", "计算本月生活费是否超支", 1000, , , , , 1)
- For Each rng In Range("b2:b31")
- isum = isum + rng
- i = i + 1
- If isum > x Then Exit For
- Next
- If isum < x Then
- MsgBox "这个月没有超支", vbOKOnly, "提醒"
- Else
- MsgBox Cells(i, 1) & "超支了:" & isum - x & "元", vbExclamation, "超支了"
- End If
- End Sub
- Sub 作业之DoWhile循环()
- Dim i As Integer, isum As Double
- Dim x As Double
- x = Application.InputBox("请输入生产费", "计算本月生活费是否超支", 1000, , , , , 1)
- i = 1
- Do While isum < x And i < 31
- '当isum<生产费与i<31时循环,只要一个条件不满足退出循环
- i = i + 1
- isum = isum + Cells(i, 2)
- Loop
- If isum < x Then
- '判断isum与生产费的大小
- MsgBox "这个月没有超支", vbOKOnly, "提醒"
- Else
- MsgBox Cells(i, 1) & "超支了:" & isum - x & "元", vbExclamation, "超支了"
- End If
- End Sub
- Sub 作业之DoUntil循环()
- Dim i As Integer, isum As Double
- Dim x As Double
- x = Application.InputBox("请输入生产费", "计算本月生活费是否超支", 1000, , , , , 1)
- i = 1
- Do Until isum > x Or i > 31
- '当isum>生产费或i>31时循环,只要一个条件满足退出循环
- i = i + 1
- isum = isum + Cells(i, 2)
- Loop
- If isum < x Then
- MsgBox "这个月没有超支", vbOKOnly, "提醒"
- Else
- MsgBox Cells(i, 1) & "超支了:" & isum - x & "元", vbExclamation, "超支了"
- End If
- End Sub
复制代码 |
评分
-
查看全部评分
|