For Each yy In Worksheets(ws).Range(Cells(8, 1), Cells(8, 160))
If yy.Value = “Stop” Then
yy.Select
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.
cheers
Simon
Tuesday, 6th September, 2011 at 11:15 pm |
Don’t know about the yy, but I’ve got the jj figured out: http://www.dynomitejj.com/
Wednesday, 7th September, 2011 at 6:21 am |
In the middle of the keyboard, both of them.
Just laziness and lack of any appreciation for good practice.
Wednesday, 7th September, 2011 at 9:23 am |
hmmm, sorry it doesnt appear indented anymore.
Wednesday, 7th September, 2011 at 9:51 am |
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…)
Wednesday, 7th September, 2011 at 10:22 am |
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).
Wednesday, 7th September, 2011 at 10:23 am |
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.
Wednesday, 7th September, 2011 at 1:12 pm |
For that matter, what does the code even do?
Thursday, 8th September, 2011 at 7:42 am |
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.
Thursday, 8th September, 2011 at 8:12 am |
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?
Thursday, 8th September, 2011 at 2:16 pm |
Gadzooks, just use the Find method instead of looping. And use better variable names too. Oh well…
Thursday, 8th September, 2011 at 5:06 pm |
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.
Dick
Friday, 9th September, 2011 at 12:17 am |
i for the outer loop, ii for the inner loop, I like that!
Friday, 9th September, 2011 at 12:24 am |
Thanx Bob … I thought it kinda makes sense and is easy to read.
Monday, 12th September, 2011 at 3:13 pm |
“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.
Monday, 12th September, 2011 at 7:51 pm |
harsh but fair DB
Wednesday, 14th September, 2011 at 1:36 am |
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.
Wednesday, 14th September, 2011 at 6:37 am |
Jim’s point reinforces DB’s, better to be explicit: Workbooks(wkbk).Worksheets(ws).Cells(8,1).Resize(1,160)