how to use arithmetic calculations in userform text boxes

sateesh kumar

Board Regular
Joined
Dec 5, 2013
Messages
63
hi all

Wish you happy new year to all :-)

am new to VBA, am creating User form, in that i want to calculate sum, sub, multiplication, %.. etc based other text box values.
am facing problem with % calculations.


Thanks in advance ..

 
here is my total code.
where am getting zero values is colored in these code..

Try this subroutines for debugging, what is in the MsgBox?
Rich (BB code):
Private Sub ServTaxTDS_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  Val(ServiceTax) = Val(ServiceTax) - Val(ServiceTax)
  MsgBox "ServiceTax = " & ServiceTax & vbLf _
       & "TdsPer = " & TdsPer & vbLf _
       & "ServTaxTDS = " & ServTaxTDS
  Debug.Print Val(ServiceTax), Val(ServiceTax), Val(ServiceTax)
End Sub
 
 
Private Sub TdsPer_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  TdsPer = Val(SalePrice.Value) + Val(ServiceTax.Value) / 10
  MsgBox "SalePrice = " & SalePrice & vbLf _
       & "ServiceTax = " & ServiceTax & vbLf _
       & "TdsPer = " & TdsPer
  Debug.Print Val(SalePrice), Val(ServiceTax), TdsPer
End Sub
 
Last edited:
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
hi ZVI
last question for these end of day
how to decrease decimal values ..
if Text box contain 943.89 it will convert into 943.9 or
if Text box contain 943.1232132, it will show 943.## only?

Thanks for advance
 
Upvote 0
hi ZVI
last question for these end of day
how to decrease decimal values ..
if Text box contain 943.89 it will convert into 943.9 or
if Text box contain 943.1232132, it will show 943.## only?

Thanks for advance
Use Format function, for example TextBox1 = Format(Val(TextBox1), "#0.00") and so on
 
Upvote 0
how can i get text along with background colour in textbox.
it will paste in excel sheet also.

thanks for advance
How to change background color of control - see the example in post #10.
To paste value from TextBox1 use Range("A1").Value = Val(TextBox1)
 
Upvote 0
hi ZVI

am again facing same problem, as expected Result is not getting for this code

am expected result is IntCllPer=2288.39874081847 but am getting 2269.455936
STandTDS= 786.8 but -786.8
Billamtfrmclient 70786.8 but 69213.2
.....etc


Code:
Private Sub CTerms_Exit(ByVal Cancel As MSForms.ReturnBoolean)
IntFact = Val(18 / 100 / 365) * Val(CTerms)
IntFact = Format(Val(IntFact), "#0.00000")


If CmpMargFigPM > CmpMargFigPM Then
MaxamtNoInt = Val(RateFromClienPM) - (Val(CmpMargFigPM) + Val(Stax))
MaxamtNoInt = Format(Val(MaxamtNoInt), "#0.000")
Else
MaxamtNoInt = Val(RateFromClienPM) - (Val(CmpnyMarginPM) + Val(Stax))
MaxamtNoInt = Format(Val(MaxamtNoInt), "#0.000")
End If


MaxCTC = Val(MaxamtNoInt) / 1 + Val(IntFact)
MaxCTC = Format(Val(MaxCTC), "0.0000")
IntCllPer.Value = CDbl(MaxCTC.Value) * CDbl(IntFact.Value)
IntCllPer = Format(Val(IntCllPer), "#0.000")

Private Sub CNegot_Exit(ByVal Cancel As MSForms.ReturnBoolean)
CTCAftNegot = Val(CNegot) + Val(MaxCTC)
Tds = (Val(RateFromClienPM) + Val(Stax)) / 10
STandTDS = Val(Tds) - Val(Stax)
Billamtfrmclient = Val(RateFromClienPM) + Val(STandTDS)
Expenses = (Val(CTCAftNego) + Val(Stax)) + (Val(IntFact) * Val(MaxamtNoInt))
Cprofit = Val(RateFromClienPM) - Val(Expenses)


If CprofitValue > 7500 Then
Approval.BackColor = RGB(0, 255, 0)
Approval.Text = "Proceed"
Else
Approval.BackColor = RGB(255, 0, 0)
Approval.Text = "Contact Manager : Punnam/Atul"
End If
End Sub


End Sub


where am done mistake, where i want change the code.

Thank for Advance
 
Last edited:
Upvote 0
To find the reason of issue try step-by-step debugging.
In this link you can read & learn how to debug the code - Chip Pearson - Debugging VBA Code

Citation from that link:
Debugging a program is one of the most important steps in software development. Knowledge of VBA's debugging tools can make debugging easier and more productive. This page describes several of VBA's built-in debugging tools you can use when testing and debugging your application.

BTW, replace Val(18 / 100 / 365) just by (18 / 100 / 365)
 
Last edited:
Upvote 0
To find the reason of issue try step-by-step debugging.
In this link you can read & learn how to debug the code - Chip Pearson - Debugging VBA Code

Citation from that link:
Debugging a program is one of the most important steps in software development. Knowledge of VBA's debugging tools can make debugging easier and more productive. This page describes several of VBA's built-in debugging tools you can use when testing and debugging your application.

BTW, replace Val(18 / 100 / 365) just by (18 / 100 / 365)

hi ZVI

i wrote correct formula , but am not getting expected output is 47601.5672865788

text box names is CTCAftNego,Stax,IntFact,MaxamtNoInt and there corresponding values 36559.5993656,8652,0.0443836,53848
here is my code

Code:
Expenses.Value = Val(CTCAftNego) + Val(Stax) + (Val(IntFact) * Val(MaxamtNoInt))
Cprofit = Val(RateFromClienPM) - Val(Expenses)

where i done the mistake

thanks for advance.
 
Upvote 0
Hi ZVI

when am use this code am getting Error "Object Requried
Code:
Expenses.Value = CDbl(CTCAftNego.Value) + CDbl(Stax.Value) + (CDbl(IntFact.Value) * CDbl(MaxamtNoInt.Value))

thanks for advance
 
Upvote 0

Forum statistics

Threads
1,222,630
Messages
6,167,191
Members
452,104
Latest member
jadethejade

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