his initialized at an arbitrary value of 1000. See this SO answerthis SO answer for a very detailed explanation of various ways to locate the last row that contains data on a worksheet. For example this would sethto the last row with data in column A:h = ActiveSheet.Range("A" & ActiveSheet.Rows.Count).End(xlUp).RowBy working off the actual last row, you avoid extraneous iterations later, and avoid having to modify your code if/when the worksheet starts containing more than 1000 rows.
We
Selectthe first cell in the 999th row, and then start looping from 1 to 999.If the
ActiveCellis empty, we move up a row; else, we... wait a minute... we reassign the loop variable back to 999??It's pretty hard to understand what's happening here, and more importantly, why - and explaining why something is happening is exactly what comments are for!
'this loop sets n to the last row with data (right?)
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/