Problems with Activex control (option button), counting values according to button marking

Asked

Viewed 108 times

0

I want to count the values according to the marking of the button, for each click on each button, I intend to add 1,2,3 in each cells A29: A31. It also serves only one cell as long as it changes the value 1,2,3 for each button clicked according to button numbering, Ex: Button 1 = "1", Button 2 = "2", Button 3 = "3". How do I do it ??inserir a descrição da imagem aqui

  • You need to use VBA, but I didn’t understand what you need. When clicking Optionbutton1, insert the value 1 in A29? And Optionbutton2 the value 2 in A30 or A29?

1 answer

2

Elienay Junior, I set this little routine down real quick... please see if it helps you:

Private Sub OptionButton1_Click()
    Range("A30").Value = ""
    Range("A31").Value = ""
    preencherCelulas (29)
End Sub

Private Sub OptionButton2_Click()
    Range("A31").Value = ""
    preencherCelulas (30)
End Sub

Private Sub OptionButton3_Click()
    preencherCelulas (31)
End Sub

Sub preencherCelulas(Limite As Long)
Dim strCelula As String
Dim bytConta As Byte

    strCelula = "A" & Limite
    bytConta = 1

    For y = 29 To Limite
        Range(strCelula).Value = bytConta
        bytConta = bytConta + 1
    Next

End Sub
  • 2

    FWIW: The statement is recommended as Long. For numerous reasons, but read this reply from Soen and understand the reason. Because in modern computers, this memory gain is not significant, and can even use the same memory as a Long in 32-bit systems. The possible errors are numerous.... Do not use Integer in the line number, if the spreadsheet is too large it will cause an overflow

  • 2

    And avoid the .Select, it is slow and susceptible to errors. Instead of Range("A31").Select: ActiveCell.Value = "" you can do Range("A31").Value = ""

  • @ Danieltakeshi, this statement as "Long" how would that be?? I am a layman in VBA, I understand very few things, I only understand even the Excel formulas from basic to advanced, I haven’t started studying VBA yet. Is this statement a variable?? or would it be in place of "Private Sub ()" ??

  • @Fabioin, I was able to assemble an Excel formula, using auxiliary cells with other formulas. But the count was separated, if Button 1 = V = value "1" if false = "0" then the count will be 1/0/0, 0/2/0, 0/0/3 and so on. I’ll take a look at that code of yours and see how it reacts

  • @Elienay Junior, okay.

  • Change of Sub preencherCelulas(Limite As Integer) for Sub preencherCelulas(Limite As Long). Or when declaring a variable Dim variavel As Long

  • @danieltakeshi, Valew!

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.