Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Calculation in textboxes on form doesn't work

0

Hello

I try showing result  in textbox4,textbox 5 based on the others textboxes after calculation.

example: 

when fill textbox1=KW 1,000.00 and textbox3 =5 then will show textbox2 =KW 200.00

at the same time I would show  in textbox4=textbox2/textbox1

example : KW 200.00/KW 1,000.00 = 20% but it just show % without number !

as to textbox5 should be textbox5=(textbox1-textbox2)*textbox4

example textbox5=(KW 1,000.00-KW 200.00)*20% =KW 160.00

I hope my requiremnt is clear to slove the problem.

thanks

Answer
Discuss

Answers

0
Selected Answer

Hello leopard,

It took my a couple of tries but I figured it out for you. At first look, I thought it was probably a syntax error - and it was.

1) The "Cdbl" is not necessary because you have declared the variables as "Double".

2) The line "val2 = CDbl . . . " was not getting a value because it was placed before the "val3 = CDbl . . . . " line; and it only needs to be "val2 = val1 / val3" and placed after the "val1" & val3" lines.

3) The line "TextBox4.Value = Format(dTotal1, "%")" is just missing a "0" before the % sign >> "0%" <<.

4) The math for TextBox5 was a bit off; changed it to "TextBox5.Value = CRR & " " & (val1 - dTotal) * dTotal1"

I have made these changes in the attached file.

Cheers   :-)

Discuss

Discussion

Hi Willie , 
now it calculates as I want it except one thing is numberformat.
when show result number in textbox5 should be KW #,##0.00.
leopard (rep: 96) Oct 23, '24 at 4:12 am
Hi leopard,

Simple fix: I just changed the line: "TextBox5.Value = . . . " to the following:
TextBox5.Value = CRR & " " & Format(((val1 - dTotal) * dTotal1), "#,##0.00")

The updated file ( Rev2 ) is attached to my answer above.

Cheers   :-)
WillieD24 (rep: 657) Oct 23, '24 at 9:59 am
Thank you so much ,
leopard (rep: 96) Oct 23, '24 at 12:29 pm
You are very welcome, glad I was able to help.
Thanks for selecting my answer.
WillieD24 (rep: 657) Oct 23, '24 at 12:34 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login