I have a spreadsheet that is needed to track many approvals in different locations but all using the same macro so I have used the application.caller function to determine depending what button is pressed that specific cell will be edited:
Sub Approval()
BR = ActiveSheet.Buttons(Application.Caller).TopLeftCell.Row
BC = ActiveSheet.Buttons(Application.Caller).TopLeftCell.Column
Set WSHnet = CreateObject("WScript.Network")
UserName = WSHnet.UserName
UserDomain = WSHnet.UserDomain
Set objUser = GetObject("WinNT: forwardslash forwardslash" & UserDomain & "/" & UserName & ",user")
UserFullName = objUser.FullName
UserId = Environ("UserName")
valueAdd = "Approved By " & UserFullName & " (" & UserId & ")" & " on " & Date
Cells(BR, BC).Value = valueAdd
ActiveSheet.Buttons(Application.Caller).Visible = False
End Sub
After the approval button is pressed it records the user info in the cell and the button disappears. All of this is working perfectly.
What I also need is in the adjacent cell of each approval button is a reset button that will clear the cell and make the approval button visible again. I have tried something like this:
Sub Reset()
BR = ActiveSheet.Buttons(Application.Caller).TopLeftCell.Row
BC = ActiveSheet.Buttons(Application.Caller).TopLeftCell.Column
For Each Cell In Range(Cells(BR, BC - 2), Cells(BR, BC - 1))
ActiveSheet.Buttons().Visible = True
Cells(BR, BC - 1) = ""
Next Cell
End Sub
The red part is what is not working for me. It is making all the approval buttons on the sheet visible when I only want the button in the adjacent cell to reappear. (I am using the range of Cells(BR, BC - 2), Cells(BR, BC - 1) since I have a couple merged cells that the approval is recorded in).
I cant realistically use button names as since I have so many approvals to track it would require a distinct macro for each one, wouldn't it?
Bookmarks