Forum Discussion
rbalza
Jul 12, 2021Brass Contributor
Cell as a button
Hi Friends, What were the ways to make a cell a button? I was trying to count the text in a button but don't actually know how to do it. Thanks 🙂
- Jul 12, 2021
Right-click the sheet tab.
Select 'View Code' from the context menu.
I created a Worksheet_BeforeDoubleClick event procedure. This is run automatically each time you double-click a cell.
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) If Not Intersect(Range("B2:B20"), Target) Is Nothing Then Cancel = True Select Case Target.Value Case "X" Target.Value = "P" Case "O" Target.Value = "X" Case Else Target.Value = "O" End Select End If End Sub
The code first checks whether the cell is in the range B2:B20.
If so, it sets Cancel to True to prevent going into edit mode.
Then it changes the value of the cell depending on the current value.
HansVogelaar
Jul 12, 2021MVP
I'm afraid I don't understand your question. Can you explain in detail what you want to happen?
- rbalzaJul 12, 2021Brass ContributorHi Hans, would like to actually include the text on the button on the countif formula. As you can see on the snippet, the "x" mark were counted as 2 using countif formula. Hence, would like to know the workaround if we can include on the countif whatever the text on the button is selected.
- HansVogelaarJul 12, 2021MVP
See the attached version.
- rbalzaJul 12, 2021Brass ContributorHi Hans, much appreciated it. I kinda get how it works. However, is there an efficient way to do say if I have multiple buttons in it? What I was trying to do is that, fill the cells with multiple buttons and count how many 'x' were there.