Search code examples
excelvariablesexcel-2013vba

Variable Declaration Lists


I have a macro that I am beginning to program and had a question about declaring the variables.

So far this is what I have:

Dim wbTHMacro As Workbook
Dim wsRegulares As Worksheet
Dim wsRegularesDemitidos As Worksheet
Dim wsTempActivos As Worksheet
Dim wsTempJA As Worksheet
Dim wsTempFit As Worksheet
Dim wsTempDemitidos As Worksheet
Dim wsPresenceSystem As Worksheet
Dim wsResultados As Worksheet
Dim wsDLList As Worksheet
Dim wbRegularesBruto As Workbook

Because I will have many more variables is it possible to just write them out long ways across instead of list them down to make my macro shorter? If so, How? they go into the next line how would I space or give continuation?

Any help would be greatly appreciated.


Solution

  • You can do it like this:

    Dim wbTHMacro As Workbook, wsRegulares As Worksheet, wsRegularesDemitidos As Worksheet
    Dim wsTempActivos As Worksheet, wsTempJA As Worksheet, wsTempFit As Worksheet
    Dim wsTempDemitidos As Worksheet, wsPresenceSystem As Worksheet, wsResultados As Worksheet
    Dim wsDLList As Worksheet, wbRegularesBruto As Workbook
    

    Personally, I rather like to declare my variables near the first time I use them. I find it easier to debug.