Can I do a counter in macros that registers me accounts times a macro is executed?

2

I would like to know if you can do a counter or a boolean that changes every time a macro is executed, since I need to make a conditional that validates if a macro was executed to perform a certain action.

note: the counter will be used in a different macro, that is, in another module.

    
asked by andrez restrepo 14.09.2016 в 21:27
source

2 answers

2

You can use an accumulator and assign it a value once the instructions are finished and then put that value in a cell. It would be as follows:

    Sub mi_macro
    ...(instrucciones)...
    acumulador=acumulador+1
    Cells(100,100).value(acumulador)   // Se entiende 100,100 por asignar una celda que no esté en uso en la planilla. 
    End Sub

Then you go to the cell (100,100) and you take the value.

    
answered by 14.09.2016 / 21:49
source
0

If the range is modified you can use a combination of functions to obtain the index of the row (or column) where the cursor is positioned. You can use the "Selection.End (xlRight) .Select" and "ActiveCell.Column". Find out more about the variations of these commands and maybe they can be very useful. I use: "Selection.End (xlDown) .Select" and I use the "ActiveCell.Row" to get the index of the last row of the pivot table.

    
answered by 14.09.2016 в 22:07