vba - Why does this Worksheet_change loop crash if row insert causes number of rows > 100? -


the purpose of below code number rows 6 rowcount 1 rowcount in numerical order in col b. when user inserts row, numbers automatically adjust. example, if user inserts new row between rows 6 , 7, new row numbered 7 in col b, previous row 7 renumbered 8, , remaining rows renumbered 9 rowcount. works fine until rowcount >= 100. when user inserts new row, program crashes. why? what's special 100 , above? there better method auto re-renumbering rows when user inserts new row?

private sub worksheet_change(byval target range)  dim long, rowcount long  rowcount = usedrange.rows.count  = 6 rowcount     if me.cells(i, 2) <> - 5         me.cells(i, 2) = - 5     end if next 

works fine here,

option explicit  private sub worksheet_change(byval target range) application.enableevents = false dim long = 6 usedrange.rows.count     if me.cells(i, 2) <> - 5 me.cells(i, 2) = - 5     end if next application.enableevents = true end sub '[![screenshot][1]][2] 

screenshot


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -