Trueblue862
Board Regular
- Joined
- May 24, 2020
- Messages
- 160
- Office Version
- 365
- Platform
- Windows
Hi, over the past 12 months or so I have been slowly teaching myself to code, using this site as my lifting off point. I have to say thank you for all the help I have received and I'm sure I have frustrated more than a few of the members here, and probably will more into the future, for this I apologise. Anyway, last week I heard of the fizzbuzz test for the first time, and I had a bit of time on my hands today so I thought I would give it a crack. It took me a little head scratching but I eventually got it. The main part I had trouble with was evaluating whole numbers, once I had that down it worked perfectly, mind you it took more time than I care to admit. Although I fully understand there are many ways to attack this problem, and I know mine isn't the best, I would like to hear from some of the gurus here as to what their opinions are of my code and ways I could go about improving further. Thank you to all the excellent contributors to this forum for getting me this far.
VBA Code:
Sub fizzBUZZ()
Dim cl As Range
Dim x As Variant
Dim y As Variant
i = 1
Set cl = Sheets("Sheet1").Range("A1:A100")
For Each cl In cl
x = i / 3
y = i / 5
If x = Int(x) And y = Int(y) Then
cl.Value = "FIZZBUZZ"
ElseIf x = Int(x) Then
cl.Value = "FIZZ"
ElseIf y = Int(y) Then
cl.Value = "BUZZ"
ElseIf x <> Int(x) And y <> Int(y) Then
cl.Value = i
End If
i = i + 1
If i > 100 Then GoTo thr
Next
thr:
End Sub