This macro is supposed to look down column B and see if the value in each cell is greater than the value to the right(in column C). If so, it should color the cell. But it doesn't work!!! Help
Please Login or Register to view this content.
This macro is supposed to look down column B and see if the value in each cell is greater than the value to the right(in column C). If so, it should color the cell. But it doesn't work!!! Help
Please Login or Register to view this content.
Last edited by vlady; 12-04-2012 at 08:53 PM. Reason: code tags
Where is the loop (i) in the code?
Move out the count up, otherwise, you are going back to 2 each time you loop thr. Stack with 2 for ever
Please Login or Register to view this content.
Last edited by AB33; 12-04-2012 at 06:46 PM.
AB33's answer is correct. But why are you using two counter variables? You only need one
In the future you can solve these kinds of problems yourself by using VBA's debugger. Set a watch on the variable of interest (in this case count) and then step through the code by pressing F8. You'd see that the variable value kept being reset every time you re-entered the for loop.Please Login or Register to view this content.
Last edited by DobbsHead; 12-04-2012 at 06:57 PM.
With i
Please Login or Register to view this content.
haha. That was a pretty retarded mistake. Thanks to everyone. Dobbshead, can you explain how to put a watch on a variable? I know how to execute the code line by line, but I don't know how to see what the variable is reading.
Dobbs,
My initial intention was not to came up with elegant answer but to show the OP where he/she went wrong so that to correct it themselves. Infact, I did not see your reply before I posted mine
Jiptastic,
Sure, I'd be happy to explain how to use the watch and debugger.
1) Open your code in the VBA editor
2) Select the variable or expression you wish to watch. (i.e. you can watch the result of an expression, like: Range("A2").value)
3) Right click and select "add watch". You will then see that variable appear in the current watches menu.
4) Open the debug menu and select "Step Into", press F8 to see your code execute line by line
That should get you started. You should experiment with the options in the debug menu. For example, you can add breaks to you code so that it stops at the same point every time, rather than having to step through everything.
@AB33
After reading my original post I realized it read snarkier than I intended, so I revised it. I apologize.
DobbsHead. Thanks!! That will help alot in solving these sort of problems myself.
AB33 thanks for answering my question on why it wasn't looping. Now I will watch out for that newbie mistake and I will stop using more variables than necessary so I can be more elegant as well.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks