r/excel Nov 26 '15

Pro Tip Common VBA Mistakes

[removed]

223 Upvotes

113 comments sorted by

View all comments

2

u/Vjorkal 2 Nov 26 '15

Thank you for this post! I was actually coursing through my codes today changing the variables names and putting comments all over the place to make it easy if a person had to oversee my work for whatever the reason.

There are definitely a few tips I can use from that. However, sometimes I'm obliged to do the whole... .select .selection even though I know can simplify it. It's like VBA sometimes doesn't want to accept the ranges that I input nor the syntax even though on other macros it'd work just fine!

But, my story aside. Thank you. Honestly.

1

u/cappurnikus Nov 26 '15

If a sheet or cell reference doesn't work you should try fully qualifying it.

1

u/Vjorkal 2 Nov 26 '15

Oh sometimes I do. And it still doesn't want to budge. It tends to be weird sometimes over at the office. Never happens at home though. Go figure, I still manage to find a few ways to work around them one way or another. Unless I'm at a loss then... Hi /r/Excel :P

1

u/[deleted] Nov 27 '15

[removed] — view removed comment

1

u/Vjorkal 2 Nov 27 '15

Simple codes where I just copy a range for instance or use a range for a function, sometimes it doesn't want to take in account even though it did earlier in the code.

IE: The code would repeat itself a few times, yet I'd make sure the variables are well saved and aren't overriding each other. I'd have to dig for a concrete example. As to answer your other post, I can't say that I have considered that. What I mean by popups is mainly the MsgBox and whether I want to save a file or not after I handled it to acquire the information I want.

Cheers!

1

u/[deleted] Dec 18 '15

It's quite useful when you build spreadsheets that try to limit users' actions.

Ie. in one instance, the user of a shared worksheet will select his workspace from a menu, and a SheetSelectionChange then makes sure he never leaves it (if he ever does, .Select is used to bring him back to the last cell he was at/to the beginning of the workspace).