command button calculation

bronwyn

Board Regular
Joined
Jun 12, 2004
Messages
93
hi all, what im trying to achieve is to have a command button, which will take input from a textbox, and calculate results and display in textbox2. the calculation will be whatever number is entered in textbox1, divide this number by 18 and multiply it by 40. i know i can achieve this with formulas, but need to use vba and commands from toolbox to achieve this, as alwasy any help appreciated
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi bronwyn,

try this one in a seperate module:

Code:
Option Explicit

Sub test()
 If IsNumeric(ActiveSheet.TextBox1.Value) And IsEmpty(ActiveSheet.TextBox1) = False Then
   ActiveSheet.TextBox2.Value = ActiveSheet.TextBox1.Value / 18 * 40
 Else
   MsgBox "Please check TextBox1"
   ActiveSheet.TextBox2.Value = ""
 End If
End Sub

EDIT: I think you´re able to chang my code for working with a command button... If not:
Code:
Option Explicit

Private Sub CommandButton1_Click()
 If IsNumeric(ActiveSheet.TextBox1.Value) And IsEmpty(ActiveSheet.TextBox1) = False Then
   ActiveSheet.TextBox2.Value = ActiveSheet.TextBox1.Value / 18 * 40
 Else
   MsgBox "Please check TextBox1"
   ActiveSheet.TextBox2.Value = ""
 End If
End Sub
 
Upvote 0
assuming that your command button is named "cmd_Calculate"... Just kick the following code:

Private Sub Cmd_Calculate()
TextBox2.Text = TextBox1.Text / 18 * 40
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,199
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top