View Full Version : [SOLVED:] Adding odd numbers in VBA
loloobaloo
06-23-2022, 12:52 AM
Hi friends I am working on a code that adding odd number from 1 to the number user determines. I did the adding number but I don't know how I should do it for odd number. I hope anybody can help me.
In attachment you can find what I've done.
georgiboy
06-23-2022, 12:59 AM
Maybe just add a step to your loop:
Sub OddNumber() Dim num As Integer
Dim Sum As Long
Dim i As Long
num = InputBox("Enter your number")
Range("A1").Value = num
For i = 1 To num Step 2
Sum = Sum + i
Next
Range("A2").Value = Sum
End Sub
loloobaloo
06-23-2022, 01:11 AM
Thanks it works.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.