MaliA wrote:
Kern wrote:
MaliA wrote:
I've written 109 lines of code today (OK, I've left a lot of notes in it, but y'know, they need to be there for quick and easy reference)...
EDIT: What takes me about 35 minutes to do, now takes 3 seconds, if that, using the thingymabob
Careful, you might automate yourself out of a job. Best take the comments out and introduce a random subroutine that turns it all purple or sonething which only you can take over.
(And yes, I'm just jealous of your VBA skills: I currently have a series of routines which could, with tweaking, do AMAZING things, but have yet to apply them to my current project)
Best tip form my book so far: Use the macro recorder to,um, record a macro, then ALT F11 to have a look at it in the editor. Then remove lines at random, by sticking an apostrophe in front of them, and see if it still works.
This is pretty much how I learnt, and it seems to get me by.
Unless you have a stupid looking spreadsheet with data all over the place, you should be able to get Excel to tell you the last used row, without having to iterate through all the rows to check whether or not they're populated.
Something like
Code:
lastrow = range("a65536").End(xlUp).row
will pass the last used cell in column a (so you could swap that for a different column if it helps) to the lastrow variable and you can then make use of that wherever the macro has used the specific range.
So if your code says something like:
Code:
Range("A1:E13").Select
you could change it to
Code:
Range("A1:E" & lastrow).Select
and it should always pick up the right number of rows.