The most basic question ever - what does "i" mean

J

jknapp1005

Bill Jelen wrote a book for VBA in Excel 2007. I guess he thinks I know
everything. He is writing things and not explaining what they are. All the
sudden he's writing section of macros that say things like:

FinalRow = Cells(Rows.Count, 1). End(xlUp).Row
For i = 1 to FinalRow
Range ("A" & i & ":E" & i).Font.Bold = True
Next i

without explaining what the heck "i" means. Try searching for the meaning of
"i" in any database.
 
D

Dave Peterson

i is a variable. The name was Bill's choice--almost arbitrary. He wouldn't use
a variable named Long, Integer, Row, Font, Bold or any thing built into excel's
VBA--or any illegal name (VBA's help will explain more).

In this case, I bet Bill has a line like:
Dim i As Long
(or "Dim i as integer")
in his code

In this case, it's a place holder that he can use for looping between the number
1 and the number that's stored in that FinalRow (another variable).

So for the first time through (when i = 1):
Range ("A" & 1 & ":E" & 1).Font.Bold = True
which is:
Range ("A1":E1").Font.Bold = True

The 2nd time through, i = 2:
Range ("A" & 2 & ":E" & 2).Font.Bold = True
which is:
Range ("A2":E2").Font.Bold = True

If he had 1000 rows to bold, it would be very ugly to use 1000 lines like:

Range ("A1":E1").Font.Bold = True
Range ("A2":E2").Font.Bold = True
Range ("A3":E3").Font.Bold = True
Range ("A4":E4").Font.Bold = True
...
Range ("A1000":E1000").Font.Bold = True
 
J

jknapp1005

Sorry, smartin, not meaning to be trollish. Actually, I DID spend a good hour
trying to find some definition of "i". It may seem obvious to you folks, but
as someone who is fairly new, it is isn't really obvious to me. I do realize
to those who are experienced, it would seem like a basic question. But I
looked in the index, online, in the VBA editor window, and couldn't find
anything that described it. I even referenced other's books, and didn't see
it being used.

Yeah, sometimes the most basic things do escape me. Thanks for posting.
 
J

jknapp1005

That's a very good answer. Thank you very much.

smartin said:
witek said:
O yes, it is really about complex numbers.


:)

Actually, the code is imaginary. There can be no "FinalRow" because
there is always one more row. This concept has been demonstrated many
times. For a perfect example you can read this:
http://mathschallenge.net/index.php?section=faq&ref=number/infinite_primes
but this is a much more succinct proof:

If we write
For i = 1 to FinalRow
...
Next i

It is the same as
i = 1
While i <= FinalRow ' Note 1
...
i = i + 1 ' Note 2
Wend

Note 1: Aha! i is the duck that eats i + 1, so i always gets bigger
[especially when cheeseburgers are nearby], so FinalRow must be a
nondecreasing function of i. Therefore as i go, you go.

Note 2: Now, how can i = i + 1, really ??? There are only two
possibilities: either FinalRow is unbound, so either i = infinity, or
1=2. I think the latter can be proved, but I've lost my notes on that
one. So the former must be true. However if you have so many rows that
Excel craps out, you have a cheeseburger, and then the next row is
imagined: QED.
 
J

jknapp1005

That's really great, actually. I couldn't find anything like that. Although
you guys are having fun takin' shots (which I'm sure I deserve), I actually
learned something from that. Thanks.
 
J

jknapp1005

Thanks. Very helpful.

witek said:
iterator - a variable which changes its value (usually by 1) in every
iteration of the loop.
"i" was the simplest what could be chosen to name iterator


check also Hungarian notation.
It has something to do with International Space Station :)
 
J

jknapp1005

Thanks, Dave. You were much gentler on me than I probably deserved. Sometimes
the simplest things are the most frustrating (for me anyway). Thanks very
much!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top