tags:

views:

358

answers:

3

How can I count to 10 while summing the numbers in VBA?

+5  A: 
Dim Sum as Integer
Sum = 0 

Dim I as Integer

For I = 1 to 10
    Sum = Sum + I
Next

Edit: For future reference, please refer to Microsoft's MSDN section on Visual Basic for Applications (VBA)

TheTXI
Thank you, this was really hard.
Janie
Dim Sum, LOL ;)
WowtaH
Hee hee, Lunchtime!!!
Janie
Mmmmm, dim sum!
gnovice
+4  A: 

The question is labeled VB6, so:

Dim Sum As Integer
Dim i As Integer
For i = 1 To 10
    Sum = Sum + i
Next i
Jay Riggs
@A: if you're really not worried about verbosity, use `theVariableImUsingToCountToTenWith` instead of `i`
Shog9
I like the anal retentive verbosity advocate who only uses his initial for his first name.
Geoffrey Chetwood
@Shog9: if you're really not worried about verbosity, use 'iHaveNoIdeaWhetherThisWouldWorkAsAPossibleVariableNameInVBASoIGuessItIsWorthAShotSoIAmCreatingASuperLongVariableNameToHoldSoThatICanWriteAForLoopFromOneToTen'
TheTXI
A: 

Why do you need to use VBA to do this, your using excel, couldn't you just put the numbers 1 to 10 in different cells and add them up. Why do you even need to use excel. Couldn't you just type 1+2+3+4+5+6+7+8+9+10 into a calculator. Why do you even need to use a calculator, why can't you just work it out in your head.

Andrew Marsh
If I had downvotes left, I'd downvote you just for being extremely late to this party.
TheTXI
Some of us can't handle two-digit addition in our heads, you insensitive clod.
Pesto
Um, because i'm trying to LEARN VBA. I'm familiar with calculators, thanks.
Janie