I want to create a macro which works in each sheet of my excel file. The nth time that macro is used in the mth sheet the macro write something in the nth cell of the mth sheet.
If I only had a sheet, I would use a global variable in my code
Dim cellToBeChanged As String
Sub macro()
If cellToBeChanged = "" Then
cellToBeChanged = "A1"
else
cellToBeChanged =Range(cellToBeChanged).Offset(1, 0).Address
end if
‘write what needs to be written in cellToBeChanged
End Sub
But if I have more than one sheet, this code doesn’t work.
For instance if I used this macro the first time in tab 1, and then in tab 2, and then in tab 3. There is 2 cells in tab1 in a1 and a3 and 1 cell in tab2 in a2 instead of 2 cell in a1, a2 in tab1 and a cell in a1 in tab2
I could a different variable for each sheet. But I will probably create a lot of sheet.
In addition of that what I call the nth row will perhaps not be nthLetterOfTHeAlphabet. I am looking for something more general to store that in the nth Sheet, the Macro has been used mth time
How should I write my macro to make her behave as I would like?