why why?

For Each yy In Worksheets(ws).Range(Cells(8, 1), Cells(8, 160))
If yy.Value = “Stop” Then
jj = yy.Column
End If
Next yy

Why would you use yy ? (nervous twitch??) (or jj)

Also note how I have generously indented it for your delight, unlike the original.




17 Responses to “why why?”

  1. Keith A. Lewis Says:

    Don’t know about the yy, but I’ve got the jj figured out: http://www.dynomitejj.com/

  2. Robert Bruce Says:

    In the middle of the keyboard, both of them.

    Just laziness and lack of any appreciation for good practice.

  3. Simon Says:

    hmmm, sorry it doesnt appear indented anymore.

  4. Marcus from London Says:

    Well, of course it’s obvious Simon. ‘y’ by itself would be meaningless. Having ‘yy’ makes the variable more meaningful and the code easier to read :P

    In reality I can’t think of any rationale for the naming (itchy trigger finger aside). It’s no clearer than a single character and probably makes the code harder to read should you extend the laziness using the same repeated character for different variables (e.g. j, jj, jjj, jjjj…)

  5. Bob Phillips Says:

    Like everyone else I am sure, I use i, and j for loop control, but when I was first learning Cobol (yes, I really did!), one of the other programmers always used single letter names for their variables, all variables. That was hard code to follow (but not as hard as the electoral registration suite that was written using a swathe of alterable gotos).

  6. Simon Says:

    I wrote a VBA obfuscator that changes all variable names to some combination of a,e,o with various accents. This code wouldnt need it…
    a, aa, aaa, b, bb, bbb etc I could understand (the choice – not the resulting code) they are related, but yy, jj, A, D, E – there is no pattern.

  7. JP Says:

    For that matter, what does the code even do?

  8. Martin David Rushton Says:

    Its finding the number of the last column where row 8 has the word stop in it as long as it occurs before column 160 and selecting that cell. As in theory it could too have selected 159 other cells first which also makes it very inefficient.

  9. mikewoodhouse Says:

    I’d guess that there may at some time have been xx and ii variables. And the reason for the doubling is obvious: single-letter variable names are *always* bad, aren’t they?

  10. JP Says:

    Gadzooks, just use the Find method instead of looping. And use better variable names too. Oh well…

  11. Biggus Dickus Says:

    This does seem a bit strange to me but each to their own I guess.

    Personally I use my own strange little naming protocol where in a procedure I use a “c” to indicate a cell, “i” to indicate an item on a list, etc., etc. Then if I have a loop within a loop I go to “cc” or “ii” and then “ccc” or “iii” etc. Then I indent accordingly.

    Maybe not the purest form, but the use of multiple characters inside a loop is useful to me and using the letters like “c” for cells frankly just keeps me from having to decide what the heck I will name the variable this time :-) …. I have more important things to think about than naming conventions when trying to create a working spreadsheet in the quickest possible time.


  12. Bob Phillips Says:

    i for the outer loop, ii for the inner loop, I like that!

  13. Dashing Blade Says:

    “Why would you use yy ? ” . . .

    Because the person is a crap coder. End Of.

    It’s rubbish like that that gives spreadsheet solutions a bad name.

  14. Simon Says:

    harsh but fair DB

  15. Jim Cone Says:

    What is bothersome is not specifying the parent object for “Cells”. That code is going to be a real problem if “ws” is not the active sheet.

  16. lhm Says:

    Jim’s point reinforces DB’s, better to be explicit: Workbooks(wkbk).Worksheets(ws).Cells(8,1).Resize(1,160)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: