VBA Clear textboxes problem...

paroduso

Board Regular
Joined
Sep 11, 2013
Messages
77
Office Version
  1. 2019
Platform
  1. Windows
Hi everyone...im facing a problem when triyng to clear all the textboxes with a click event...
i triyed a loto of codes and none of them worked...with this exemple im facing a overflow error...


VBA Code:
Private Sub TextBox1_Change()

TextBox3 = TextBox1

TextBox7 = Val(TextBox6) / Val(TextBox3) * Val(TextBox4) * Val(TextBox5)
TextBox7 = Replace(Format(Val(TextBox6) / Val(TextBox3) * Val(TextBox4) * Val(TextBox5), "0.0000"), ",", ".")

End Sub

Private Sub TextBox2_AfterUpdate()

TextBox3 = CDbl(TextBox1) + CDbl(TextBox2)

TextBox7 = Val(TextBox6) / Val(TextBox3) * Val(TextBox4) * Val(TextBox5)
TextBox7 = Replace(Format(Val(TextBox6) / Val(TextBox3) * Val(TextBox4) * Val(TextBox5), "0.0000"), ",", ".")

End Sub

Private Sub TextBox3_Change()

TextBox3 = Abs(Val(TextBox1) - Val(TextBox2))

End Sub

Private Sub TextBox6_Change()

TextBox7 = Val(TextBox6) / Val(TextBox3) * Val(TextBox4) * Val(TextBox5)
TextBox7 = Replace(Format(Val(TextBox6) / Val(TextBox3) * Val(TextBox4) * Val(TextBox5), "0.0000"), ",", ".")

End Sub

Private Sub CommandButton1_Click()

Dim x As Integer
For x = 1 To 19
   Select Case x
     Case 8, 9
         ' do nothing
     Case Else
         Me.Controls("textbox" & x).Value = ""
   End Select
Next x

End Sub

in textox4 the value must be 1.008 and textbox5 1000

can you help me?

thank you.
 
Last edited by a moderator:

Some videos you may like

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
1,295
Office Version
  1. 2013
Platform
  1. Windows
You make calculations that change the content of the various text boxes. The moment you delete the content of one of those text boxes, it directly affects the calculations to be made in those other text boxes. You might as well have gotten a division by zero message. Advice: make the desired calculations in separate procedures and place just the result in the text box. This applies to all text boxes.
 
Solution

paroduso

Board Regular
Joined
Sep 11, 2013
Messages
77
Office Version
  1. 2019
Platform
  1. Windows
You make calculations that change the content of the various text boxes. The moment you delete the content of one of those text boxes, it directly affects the calculations to be made in those other text boxes. You might as well have gotten a division by zero message. Advice: make the desired calculations in separate procedures and place just the result in the text box. This applies to all text boxes.
thank you for the reply...i was just thinking about that...thank you very mutch
 

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
1,295
Office Version
  1. 2013
Platform
  1. Windows
You are welcome and thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,107
Messages
5,622,782
Members
415,927
Latest member
vedasinternational

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
Top