ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Repetitive IF THEN Statement (https://www.excelbanter.com/excel-programming/289241-repetitive-if-then-statement.html)

Todd Huttenstine[_3_]

Repetitive IF THEN Statement
 
Below is my code:

Sub CalculateProfit()
OrderForm.TextBox119.Value = OrderForm.TextBox9.Value +
OrderForm.TextBox14.Value + OrderForm.TextBox19.Value +
OrderForm.TextBox24.Value + _
OrderForm.TextBox29.Value + OrderForm.TextBox34.Value +
OrderForm.TextBox39.Value + OrderForm.TextBox44.Value + _
OrderForm.TextBox49.Value + OrderForm.TextBox54.Value +
OrderForm.TextBox59.Value + OrderForm.TextBox64.Value + _
OrderForm.TextBox69.Value + OrderForm.TextBox74.Value +
OrderForm.TextBox79.Value + OrderForm.TextBox84.Value + _
OrderForm.TextBox89.Value + OrderForm.TextBox94.Value +
OrderForm.TextBox99.Value + OrderForm.TextBox104.Value + _
OrderForm.TextBox109.Value + OrderForm.TextBox114.Value
End Sub

Here is the problem, if anyone of the above TextBoxes.Value is "Select",
then "Select" will be 1 of the values in TextBox119. Is there anyway I can
remove or ignore all the TextBox.Values that equal "Select" without having
to write a ton of IF THEN statements?


Todd Huttenstine



Rob van Gelder[_4_]

Repetitive IF THEN Statement
 
Todd,

Sub CalculateProfit()
Dim strTemp as String

strTemp = OrderForm.TextBox9.Value + OrderForm.TextBox14.Value +
OrderForm.TextBox19.Value + OrderForm.TextBox24.Value + _
OrderForm.TextBox29.Value + OrderForm.TextBox34.Value +
OrderForm.TextBox39.Value + OrderForm.TextBox44.Value + _
OrderForm.TextBox49.Value + OrderForm.TextBox54.Value +
OrderForm.TextBox59.Value + OrderForm.TextBox64.Value + _
OrderForm.TextBox69.Value + OrderForm.TextBox74.Value +
OrderForm.TextBox79.Value + OrderForm.TextBox84.Value + _
OrderForm.TextBox89.Value + OrderForm.TextBox94.Value +
OrderForm.TextBox99.Value + OrderForm.TextBox104.Value + _
OrderForm.TextBox109.Value + OrderForm.TextBox114.Value

OrderForm.TextBox119.Value = Replace(strTemp, "Select", "")
End Sub


Rob


"Todd Huttenstine" wrote in message
...
Below is my code:

Sub CalculateProfit()
OrderForm.TextBox119.Value = OrderForm.TextBox9.Value +
OrderForm.TextBox14.Value + OrderForm.TextBox19.Value +
OrderForm.TextBox24.Value + _
OrderForm.TextBox29.Value + OrderForm.TextBox34.Value +
OrderForm.TextBox39.Value + OrderForm.TextBox44.Value + _
OrderForm.TextBox49.Value + OrderForm.TextBox54.Value +
OrderForm.TextBox59.Value + OrderForm.TextBox64.Value + _
OrderForm.TextBox69.Value + OrderForm.TextBox74.Value +
OrderForm.TextBox79.Value + OrderForm.TextBox84.Value + _
OrderForm.TextBox89.Value + OrderForm.TextBox94.Value +
OrderForm.TextBox99.Value + OrderForm.TextBox104.Value + _
OrderForm.TextBox109.Value + OrderForm.TextBox114.Value
End Sub

Here is the problem, if anyone of the above TextBoxes.Value is "Select",
then "Select" will be 1 of the values in TextBox119. Is there anyway I

can
remove or ignore all the TextBox.Values that equal "Select" without having
to write a ton of IF THEN statements?


Todd Huttenstine






All times are GMT +1. The time now is 10:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com