Thread: simplify code
View Single Post
  #4   Report Post  
David McRitchie
 
Posts: n/a
Default

Hi Matt,
Suggest you try turning off both Calculation and ScreenUpdating
and yes you do need both. You are inserting cells or rows so you
have to recalculate the sheet, and you are changing your selection,
so both are needed. It is best to write your code if possible to
avoid changing a selection, but regardless that simple change
can run circles around bad coding (that works). Combine good
coding with that and you will run much faster.
http://www.mvps.org/dmcritchie/excel...htm#slowmacros

A means of timing your macro is provided on that same page.

When inserting or deleting rows or in your case cells you want to start from
the bottom and work your way up with Step -1 see some examples in
http://www.mvps.org/dmcritchie/excel...nsertBlankRows

---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"matt" wrote in message ...
Dave,

I don't think that the automatic/manual setting can speed up the program at
all, because this data has not yet been used in any calculations, there are
only a few columns of data at this point. However, I am performing this on
835 rows, so maybe it won't get any faster with less IF statements. However,
for whatever reason, when I tried the code you suggested, I got a an error
about the Next, saying

Error: Next without For.

Does anyone know what this means, and how to bypass the problem. The code
works fine using three separate IF statements, it just seems like there
should be a way to condense them into one.