Calculations in vba

AnneM

New Member
Joined
Nov 13, 2015
Messages
27
Hi Everyone,

I have a userform with a textbox, the contents of which are determined by a formula applied to other textboxes and if certain conditions are met. The textbox that this calculation applies to is "TextPremium"

The gist of it is that I want to be able to calculate the increase in a cost if some jobs are done at higher than normal rates (i.e. out of hours)

I am struggling to get this to work at all and would be grateful if someone can help with this:


Private Sub PremiumCalc()


Dim Var1, Var2, Var3, Var4, Var5, Var6, Var7, Var8, Var9, Var10 As Double


If Text1.Value <> "" Then
Var3 = Text1.Value
Else: Var3 = 0
If Text2.Value <> "" Then
Var4 = Text2.Value
Else: Var4 = 0
If Text3.Value <> "" Then
Var5 = Text3.Value
Else: Var5 = 0
If Text4.Value <> "" Then
Var6 = Text4.Value
Else: Var6 = 0
If Text7.Value <> "" Then
Var7 = Text7.Value
Else: Var7 = 0
If Text8.Value <> "" Then
Var8 = Text8.Value
Else: Var8 = 0
If TextTotalB.Value <> "" Then
Var9 = TextTotalB.Value
Else: Var9 = 0


Var1 = (Me.TextTotalA + VarB)
Var10 = (Var3 + Var4 + Var5 + Var6 + Var7 + Var8)
Var2 = ((Var1 - Var10) * TextRate1.Value)
Me.TextPremium.Value = (Var2 + (Var3 * TextRate2.Value) + (Var4 * TextRate2.Value) + _
(Var5 * TextRate3.Value) + (Var6 * TextRate4.Value) + (Var7 * TextRate5.Value) + (Var8 * TextRate6.Value))


End If
End If
End If
End If
End If
End If
End If
End Sub

Many thanks in advance
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Textboxes carry the String Datatype so if you are trying to add numbers you must first covnert the Textbox value to a long (You can use CLong to convert to a long data type MyVariable = CLong(Me.TestTotalA.value)

If you can provide a better explanation of the error/problem or share a link it would be very helpful.
 
Upvote 0
Textboxes carry the String Datatype so if you are trying to add numbers you must first covnert the Textbox value to a long (You can use CLong to convert to a long data type MyVariable = CLong(Me.TestTotalA.value)

If you can provide a better explanation of the error/problem or share a link it would be very helpful.


Thank you for your reply.

I will work on a better explanation and re-post.

Regards,

Anne
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

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