0

I am writing some code for a very large spreadsheet. Where certain things need to go in specific places, and I am wondering what sort of statement would be faster, and what are the pro's and con's of each statement.

Here is my dilemma -

There is a massive table, which could be ranging from column A to column CD, or some other column making it disgusting to look at in one go.

I am trying to create a "lastrow" variable (Integer) to describe the bottom row of data.

At the moment I have a very inefficient if loop, reading up from the bottom -".Rows.Count)End.Up(xlUp).Row", sort of thing
and it currently re-writes the lastrow variable if it is a larger number. I just want to find a quick and easy way to find the lowest row number.

Is looping the way forward with this?

Kind Regards,

lewisthegruffalo

dyslexicgruffalo
  • 364
  • 1
  • 4
  • 18
  • `Select Case` code will be Neater in VBA – Shai Rado Jun 29 '16 at 08:24
  • I'd use select case, easier to read. See here: http://stackoverflow.com/questions/11640413/which-way-is-faster-if-elseif-or-select-case – SlowLearner Jun 29 '16 at 08:52
  • Select case is not always "easier to read", neither is it "neater". Depends on the actual code and what you are trying to achieve. The actual speed difference, if there is any at all, is insignificant between the two structures. Speed is determined by your program logic. Once you have the logic, chose the structure that makes it easier to write/read/understand the code. – vacip Jun 29 '16 at 09:09
  • Anyway, if you add an example of what you are trying to do, it might be easier to discuss this - as there is no "general answer" to this question. – vacip Jun 29 '16 at 09:10
  • Anyway, if you add an example of what you are trying to do, it might be easier to discuss this - as there is no "general answer" to this question. – vacip Jun 29 '16 at 09:11
  • @vacip, here is your example - hopefully this gives you a better idea! – dyslexicgruffalo Jun 29 '16 at 09:37
  • Using `If` or `Select case` won't make an impact on the performance here. Zero. Null. Read [this](http://stackoverflow.com/questions/11169445/error-in-finding-last-used-cell-in-vba/11169920#11169920) to find out about finding the last row. – vacip Jun 29 '16 at 10:34

0 Answers0