Select and Edit all buttons in sheet

牧云@^-^@ 提交于 2020-01-16 14:10:12

问题


The routine below allows the user to toggle where they have completed/not completed the required entry. The button text changes to Complete/Incomplete and the adjacent cell goes green/red using simple conditional formatting on the 0 or 1 value. Works fine for updating a single line.

The number of data entry rows will vary for each user (say 10 to 100) and I am trying to find a way of selecting and then changing all the buttons in the sheet to "Complete" and updating the adjacent cell to 0 or 1 in one go, should the user want to do that.

Each row is a data entry line and each cell in Column B has a button, and a 0/1 in adjacent cell in Column C.

Sub complete()
'Complete / Incomplete Buttton and Flag

Dim buttontext As String

buttontext = Application.Caller
ActiveSheet.Buttons(Application.Caller).TopLeftCell.Select
ActiveCell.Select

If ActiveSheet.Buttons(buttontext).Caption = "Mark as Incomplete" Then
    ActiveSheet.Buttons(buttontext).Caption = "Mark as Complete"
    ActiveCell.Offset(0, 1).Value = 1

    Else
    ActiveSheet.Buttons(buttontext).Caption = "Mark as Incomplete"
    ActiveCell.Offset(0, 1).Value = 0

End If

End Sub

Following code works:

Sub MarkAllComplete()
Dim btn As Button
For Each btn In ActiveSheet.Buttons
btn.Caption = "Mark as Complete"
Cells(btn.TopLeftCell.Row, btn.TopLeftCell.Column + 1) = 0
Next
End Sub

回答1:


Use this concept:

For Each btn In ActiveSheet.Buttons
    Debug.Print btn.Name, btn.TopLeftCell.Column, btn.TopLeftCell.Row
Next


来源:https://stackoverflow.com/questions/49555034/select-and-edit-all-buttons-in-sheet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!