Home > Enterprise >  How to make counting the cells with button in Excel, VBA?
How to make counting the cells with button in Excel, VBA?

Time:08-11

I'm making the simple app using the VBA code and forms in Excel. So, I need to have a simple Private Sub CommandButton1_Click() method which will call for calculation methods and write down the results in Label. How can I do this? (yes, I'm new to VBA)

Private Sub CommandButton1_Click()

MsgBox "My text here"
End Sub
Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

CommandButton1_Click
End Sub

But instead of the calling the window with my text there I need to make calculations of cells. Will it be correct if I'll write code like shown down there and somehow add the calculations of cells?

Sub Button1_Click()
 Sheet1.testing 
End Sub 

Sub testing() 
Dim ell As Object
 Dim post As String 
Dim Count As Double
 Dim cm As String

 End Sub 

CodePudding user response:

In vba editor, double-click on the command-button in the UserForm to enter the code:
If you put the sub-procedure in the module (e.g doSomething sub-procedure), you have to add the module name:

Call Module1.doSomething

Option Explicit

Private Sub CommandButton1_Click()

    Call doSomething

End Sub

'--------------------------------------

Sub doSomething()

    MsgBox "My text here"

End Sub

CodePudding user response:

@FunThomas helped me (you can see it in comments to this question). And here is the solution on my question:

Private Sub CommandButton1_Click()
testing

End Sub

Sub testing()
Dim value1
calc = value1   10

Label1 = value1   10
Dim ell As Object
 Dim post As String
Dim Count As Double
 Dim cm As String
 Dim sText As String
 

sText = Sheet1.Range("A1").Value
Label2 = sText
 
End Sub
  • Related