SOLVED

Cell as a button

%3CLINGO-SUB%20id%3D%22lingo-sub-2536609%22%20slang%3D%22en-US%22%3ECell%20as%20a%20button%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2536609%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Friends%2C%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20were%20the%20ways%20to%20make%20a%20cell%20a%20button%3F%20I%20was%20trying%20to%20count%20the%20text%20in%20a%20button%20but%20don't%20actually%20know%20how%20to%20do%20it.%20Thanks%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22rbalza_0-1626049830475.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F294909iF3DFB7BB03EA1A08%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22rbalza_0-1626049830475.png%22%20alt%3D%22rbalza_0-1626049830475.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2536609%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2537460%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20as%20a%20button%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2537460%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1098170%22%20target%3D%22_blank%22%3E%40rbalza%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI'm%20afraid%20I%20don't%20understand%20your%20question.%20Can%20you%20explain%20in%20detail%20what%20you%20want%20to%20happen%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2537553%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20as%20a%20button%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2537553%22%20slang%3D%22en-US%22%3EHi%20Hans%2C%20would%20like%20to%20actually%20include%20the%20text%20on%20the%20button%20on%20the%20countif%20formula.%20As%20you%20can%20see%20on%20the%20snippet%2C%20the%20%22x%22%20mark%20were%20counted%20as%202%20using%20countif%20formula.%20Hence%2C%20would%20like%20to%20know%20the%20workaround%20if%20we%20can%20include%20on%20the%20countif%20whatever%20the%20text%20on%20the%20button%20is%20selected.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2537609%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20as%20a%20button%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2537609%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1098170%22%20target%3D%22_blank%22%3E%40rbalza%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESee%20the%20attached%20version.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2537723%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20as%20a%20button%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2537723%22%20slang%3D%22en-US%22%3EHi%20Hans%2C%20much%20appreciated%20it.%20I%20kinda%20get%20how%20it%20works.%20However%2C%20is%20there%20an%20efficient%20way%20to%20do%20say%20if%20I%20have%20multiple%20buttons%20in%20it%3F%20What%20I%20was%20trying%20to%20do%20is%20that%2C%20fill%20the%20cells%20with%20multiple%20buttons%20and%20count%20how%20many%20'x'%20were%20there.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2537728%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20as%20a%20button%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2537728%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1098170%22%20target%3D%22_blank%22%3E%40rbalza%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAgain%2C%20I%20don't%20understand%20what%20you%20want.%20Perhaps%20a%20pivot%20table%20would%20be%20more%20efficient.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2537766%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20as%20a%20button%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2537766%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3Bkinda%20like%20this.%20Do%20I%20have%20to%20create%20multiple%20macros%20or%20there's%20an%20efficient%20way%20to%20do%20this%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22rbalza_0-1626087987667.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F295007i727722DBF41463C4%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22rbalza_0-1626087987667.png%22%20alt%3D%22rbalza_0-1626087987667.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

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

 

rbalza_0-1626049830475.png

 

12 Replies

@rbalza 

I'm afraid I don't understand your question. Can you explain in detail what you want to happen?

Hi 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.

@rbalza 

See the attached version.

Hi 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.

@rbalza 

Again, I don't understand what you want. Perhaps a pivot table would be more efficient.

@Hans Vogelaar kinda like this. Do I have to create multiple macros or there's an efficient way to do this?

 

rbalza_0-1626087987667.png

 

@rbalza 

Multiple buttons are difficult to maintain.

In the attached version, you can double-click the light-green cells to toggle between the three characters.

This is freaking awesome and this is actually what I wanted But how'd you done it?
best response confirmed by rbalza (Contributor)
Solution

@rbalza 

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.

Sorry, I was about to edit my question and realized that it's in macro What my question was, is there a way to do it by single click?

@rbalza 

It would be possible, but that would be dangerous - every time you click on or move to one of the cells, its value would change. That leaves too much room for mistakes.

@rbalza 

If, with everyone's permission, I may add my humble opinion.
My approach:
With settings: right click on the button and then under "Format control" - "Properties" - "Depending on cell position and size".
With VBA:

Private Sub posbuttons()
Dim pos1 As Range
Set pos1 = Range("d7")
With Me CommandButton1
   .Height = pos1.Height
   .Width = pos1.Width
   .Top = pos1.Top
   .Left = pos1.Left
End With
End Sub

The 10 and 5 as row and column variables in the code and the potato salad is ready! :))

 

I would be happy to know if I could help.

 

Nikolino

I know I don't know anything (Socrates)