0

I am new to VBA and was confused on where to put excel VBA code, as we can put it in the module or in the sheet itself, suppose I want to write a code which filters my raw data based on cell value in another sheet and make a chart out of it. Can I write all of this macro in the module or do I need to write the chart making and filtering module separately and call them from the sheet code? Is that compulsory?

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
av abhishiek
  • 647
  • 2
  • 11
  • 26
  • All code goes into the code sheets. Write and view code in the VB Editor. – Variatus Aug 01 '17 at 11:05
  • @Variatus I meant in the editor , should we write in the modules or in the individual sheets ( by clicking on the sheets) – av abhishiek Aug 01 '17 at 11:10
  • The worksheets' code sheets should contain code required by those sheets, especially even procedures. I would have to see your code in order to answer your question. However, I suggest that you try to place the code in standard modules first. If that's the wrong place it won't work as advertised. You can also try the other way around. – Variatus Aug 01 '17 at 11:13
  • 3
    Use a Module when the code is generic, and use the Worksheet when you need to tie it into an Event specific to that Worksheet. – braX Aug 01 '17 at 11:45
  • 1
    https://stackoverflow.com/questions/3255478/put-excel-vba-code-in-module-or-sheet and https://stackoverflow.com/questions/12955461/what-difference-does-it-make-if-one-runs-a-vba-code-in-sheets-in-thisworkboo It is a matter of opinion and experience, however, there are some best practices: https://stackoverflow.com/documentation/excel-vba/1107/vba-best-practices#t=20170801113316024155 And http://www.eusprig.org/best-practice.htm – danieltakeshi Aug 01 '17 at 11:46
  • Possible duplicate of [Put Excel-VBA code in module or sheet?](https://stackoverflow.com/questions/3255478/put-excel-vba-code-in-module-or-sheet) – Andre Aug 01 '17 at 11:56

0 Answers0