VBA Clear textboxes problem...

paroduso

Board Regular
Joined
Sep 11, 2013
Messages
103
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:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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.
 
Upvote 0
Solution
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
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,496
Members
449,089
Latest member
Raviguru

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