6
\$\begingroup\$

I'm just feeling my way around here, having had a post recently moved over from another site together with its question. While I like the idea of a place to ask specifically for improvements to working code, I also see the potential for a lazy coder to 'code dump' something like a rat's nest of recorded MS Office VBA in the hopes of getting someone to clean it up.

What are the expectations of an answer to a situation like that? Are rewrites to one or two blocked sections that address different methods sufficient to meet site standards of a quality answer or should larger or even complete rewrites be provided?

My viewpoint is generally to help the user(s) help themselves, not do their work for them. If I rewrite something like this:

    Sheets("Sheet1").Select
    Range("A1").Select
    Selection.Copy
    Sheets("Sheet2").Select
    Range("B8").Select
    ActiveWindow.SmallScroll Down:=-45
    ActiveWindow.LargeScroll ToRight:=-1
    Range("A1").Select
    ActiveSheet.Paste
    Sheets("Sheet1").Select
    Range("A2").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Sheet2").Select
    Range("A2").Select
    ActiveSheet.Paste
    Sheets("Sheet1").Select
     (etc., etc., etc. ...)

To something like,

    With Sheets("Sheet1")
      .Range("A1").Copy Destination:=Sheets("Sheet2").Range("A1")
       (you can follow this method for all of the others)
    End With

Is this a satisfactory rewrite that meets site standards? Granted, if the recorded code also included something like a .Sort operation then that should be addressed as well if an improvement could be offered.

Hmmm... might need a tag specifically for Site Standards; especially during the weaning period.

\$\endgroup\$
  • 2
    \$\begingroup\$ Your question is not quite clear to me, but short answers are acceptable! No answer can claim completeness anyways... There is no actual need to use code-blocks in an answer, since explanations and clear references are often sufficient. \$\endgroup\$ – Vogel612 Feb 25 '15 at 14:53
  • 4
    \$\begingroup\$ On a personal note, welcome to Code Review! Feel free to drop by Code Review Chat or the CR VBA chatroom. \$\endgroup\$ – RubberDuck Feb 25 '15 at 14:57
  • \$\begingroup\$ @Vogel612 - I'll edit my answer for clarity when I work out some verbiage. In short, I was wondering about site standards when dealing with recorded macro 'code dumps' which can get very repetitious and to what extent an answer should address the code as a whole. Are isolated pockets dealing with methods sufficient or should the code dump be treated as a whole? \$\endgroup\$ – user66882 Feb 25 '15 at 14:58
6
\$\begingroup\$

Yes, that would be a satisfactory answer. Answers are under no obligation to provide any code at all. A good CR would point out that Select & Activate should be avoided [insert obligatory link here]. A great one would show exactly how to do that, but again, there's no obligation to do so.

Here is an example. I recently answered a question more abstractly. I simply pointed out where there was room for improvement and how to go about it, but I didn't hold OP's hand and re-write his code for him. I could have, but I just don't have that kind of time anymore. Many reviewers here don't.

Here are some relevant Metas.

\$\endgroup\$
  • 4
    \$\begingroup\$ Hi @RubberDuck - That seems perfectly reasonable. The more answers I see, the better I get at formulating my own 'flavour' for the site. I'm accepting this as the answer if for nothing else than the one-stop-shop of all those relevant links. \$\endgroup\$ – user66882 Feb 25 '15 at 15:46
  • \$\begingroup\$ You're welcome! and I would completely agree. The best way to learn the culture is to immerse yourself in it. \$\endgroup\$ – RubberDuck Feb 25 '15 at 15:53

You must log in to answer this question.