Most of the time when you write code, you want to allow the same block of code to run a number of times. You can use looping statements in your code to do this.
Sub SumUp()
Dim n As Integer
Dim t As Integer
For n = 1 To 10
t = t + n
Range(“A1”).Value = t
Next n
MsgBox " The total is " & t
End Sub
Another example:-
Sub DoWhileNotEmpty()
Do While ActiveCell.Value <> Empty
ActiveCell.Value = ActiveCell.Value * 2
ActiveCell.Offset(1, 0).Select
Loop
End Sub
No comments:
Post a Comment