Two text boxes write in each the problem

myfe

Board Regular
Joined
Jul 1, 2012
Messages
58
Hi, </SPAN>
I have this code:</SPAN>

Private Sub TextBox135_Change()
On Error Resume Next
TextBox138.Value = Format(CDbl(TextBox135.Value) / CDbl(TextBox86.Value), "0.0000")
TextBox136.Value = Format(CDbl(TextBox90.Value) + CDbl(TextBox138.Value), "0.0000")
TextBox137.Value = Format(CDbl(TextBox136.Value) / CDbl(TextBox21.Value), "0.0000")
TextBox134.Value = Format(CDbl(TextBox137.Value) - CDbl(TextBox85.Value), "0.0000")

End Sub
Private Sub TextBox136_Change()
On Error Resume Next
TextBox137.Value = Format(CDbl(TextBox136.Value) / CDbl(TextBox21.Value), "0.0000")
TextBox134.Value = Format(CDbl(TextBox137.Value) - CDbl(TextBox85.Value), "0.0000")
TextBox138.Value = Format(CDbl(TextBox136.Value) - CDbl(TextBox90.Value), "0.0000")
TextBox135.Value = Format((CDbl(TextBox137.Value) - CDbl(TextBox90.Value)) * CDbl(TextBox86.Value), "0.0000")



it suppose to take one input and calculate for the other variables the problem is that once it writes the outputs the other text box it activates the second text box code so I keep getting the error ‘13’ and the result is the same no matter what number I put please help me to solve this problem.</SPAN>
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Thanx Andrew,

Now I don't get the error MSG .
But I went back the problem that I started with it seems like I am in a loop once I input one figure all results are stuck to an number and it does not change this the code I ended up with:


Private Sub TextBox135_Change()
Application.EnableEvents = False
On Error Resume Next
TextBox138.Value = Format(CDbl(TextBox135.Value) / CDbl(TextBox86.Value), "0.0000")
TextBox136.Value = Format(CDbl(TextBox90.Value) + CDbl(TextBox138.Value), "0.0000")
TextBox137.Value = Format(CDbl(TextBox136.Value) / CDbl(TextBox21.Value), "0.0000")
TextBox134.Value = Format(CDbl(TextBox137.Value) - CDbl(TextBox85.Value), "0.0000")
Application.EnableEvents = True
End Sub


Private Sub TextBox136_Change()
Application.EnableEvents = False
On Error Resume Next
TextBox137.Value = Format(CDbl(TextBox136.Value) / CDbl(TextBox21.Value), "0.0000")
TextBox134.Value = Format(CDbl(TextBox137.Value) - CDbl(TextBox85.Value), "0.0000")
TextBox138.Value = Format(CDbl(TextBox136.Value) - CDbl(TextBox90.Value), "0.0000")
TextBox135.Value = Format((CDbl(TextBox137.Value) - CDbl(TextBox90.Value)) * CDbl(TextBox86.Value), "0.0000")
Application.EnableEvents = True
End Sub
 
Upvote 0
Now I don't get the error MSG .
But I went back the problem that I started with it seems like I am in a loop once I input one figure all results are stuck to an number and it does not change this the code I ended up with:

Sorry, it is my fault for confusing you. When I wrote my Application.EnableEvents comment, it was because I misread Andrew's code (mainly because he chose to use a property name from the Application object as a normal variable name). What I missed from his code was this line...

Code:
Public EnableEvents As Boolean
The end result is the comment I posted earlier should not be followed. Go back to the code as originally posted by Andrew and work with that. And, using the code Andrew posted originally (in Message #6), he asked you to tell him which line caused the error.
 
Upvote 0
Thanx for the clarification Rick,</SPAN>

As for the code Andrew I put it this way:


ublic EnableEvents As Boolean
Private Sub TextBox135_Change()
If Me.EnableEvents = False Then Exit Sub
Me.EnableEvents = False
On Error Resume Next
TextBox138.Value = Format(CDbl(TextBox135.Value) / CDbl(TextBox86.Value), "0.0000")
' TextBox136.Value = Format(CDbl(TextBox90.Value) + CDbl(TextBox138.Value), "0.0000")
' TextBox137.Value = Format(CDbl(TextBox136.Value) / CDbl(TextBox21.Value), "0.0000")
' TextBox134.Value = Format(CDbl(TextBox137.Value) - CDbl(TextBox85.Value), "0.0000")
Me.EnableEvents = True
End Sub


Private Sub TextBox136_Change()
If Me.EnableEvents = False Then Exit Sub
Me.EnableEvents = False
On Error Resume Next
TextBox137.Value = Format(CDbl(TextBox136.Value) / CDbl(TextBox21.Value), "0.0000")
TextBox134.Value = Format(CDbl(TextBox137.Value) - CDbl(TextBox85.Value), "0.0000")
TextBox138.Value = Format(CDbl(TextBox136.Value) - CDbl(TextBox90.Value), "0.0000")
TextBox135.Value = Format((CDbl(TextBox137.Value) - CDbl(TextBox90.Value)) * CDbl(TextBox86.Value), "0.0000")
Me.EnableEvents = True

End Sub




There is no error but I get no results in the text box I don't know why??!!
 
Upvote 0
Hello Andrew,

If I don't get an Error MSG why do you think it does not respond to my input?</SPAN>
Though if I Comment:


If Me.EnableEvents = False Then Exit Sub
Me.EnableEvents = False
On Error Resume Next


Me.EnableEvents = True

The code works !!</SPAN>
Do I need to change something in the properties or add something at the top or set some Value in a different way ??

I would really appreciate your help guys.</SPAN>
Thanx</SPAN>
 
Upvote 0
Do you still have this code?

Code:
Private Sub UserForm_Initialize()
    Me.EnableEvents = True
End Sub

It's essential.
 
Upvote 0
I am a newbie Andrew:ROFLMAO:

I figured it would be something very basic that no one even mentions .</SPAN>
But really really THHHHHHHHHHHHHHHHHHHHHHHHHHHHANK you Andrew.</SPAN>
My project is a week late just because of these tiny 3 lines.</SPAN>

I can’t tell how happy I am it worked. </SPAN>
I was trying to make it in a different way looking for different approaches looool</SPAN>

Thanx I really appreciate it .</SPAN>
 
Upvote 0
I am a newbie Andrew:ROFLMAO:

I figured it would be something very basic that no one even mentions .</SPAN>
But really really THHHHHHHHHHHHHHHHHHHHHHHHHHHHANK you Andrew.</SPAN>
My project is a week late just because of these tiny 3 lines.</SPAN>

I can’t tell how happy I am it worked. </SPAN>
I was trying to make it in a different way looking for different approaches looool</SPAN>

Thanx I really appreciate it .</SPAN>
 
Upvote 0
Hi Anrew,

the first code worked fine with me.

Now I inserted this code and I got the same old problem though the old ones are working fine:

</SPAN>
Private Sub TextBox14_Change()
TextBox14.Text = Format(TextBox14.Text, "#,###,###")</SPAN>
If Me.EnableEvents = False Then Exit Sub
Me.EnableEvents = Fslse</SPAN>
On Error Resume Next</SPAN>
TextBox19.Value = Format(CDbl(TextBox14.Value) * CDbl(TextBox9.Value), "0.0000")
TextBox16.Value = Format(CDbl(TextBox13.Value) +CDbl(TextBox19.Value), "0.0000")
TextBox17.Value = Format(CDbl(TextBox16.Value) - CDbl(TextBox20.Value), "0.0000")
TextBox18.Value = Format(CDbl(TextBox149.Value) / CDbl(TextBox17.Value), "0.0000")</SPAN>
Me.EnableEvents = True</SPAN>
End Sub
</SPAN>
Private Sub TextBox16_Change()</SPAN>
If Me.EnableEvents = False Then Exit Sub
Me.EnableEvents = Fslse</SPAN>
On Error Resume Next</SPAN>
TextBox17.Value = Format(CDbl(TextBox16.Value) - CDbl(TextBox20.Value), "0.0000")
TextBox18.Value = Format(CDbl(TextBox149.Value) + CDbl(TextBox17.Value), "0.0000")
TextBox19.Value = Format(CDbl(TextBox13.Value) /CDbl(TextBox16.Value), "0.0000")
TextBox14.Value = Format(CDbl(TextBox19.Value) / CDbl(TextBox9.Value), "0.0000")
Me.EnableEvents = True</SPAN>
End Sub</SPAN>


if I delet one of them the other works fine so I guess I have the same problem again.
why isn't the enable event working though both ( my old code and this code) are in the same user form but in a diffrent muti page tab.
I hope you could find the solution for me.

regards</SPAN>
 
Upvote 0

Forum statistics

Threads
1,216,091
Messages
6,128,779
Members
449,468
Latest member
AGreen17

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