Can Not Pass Value from Textbox to Formula

drmingle

Board Regular
Joined
Oct 5, 2009
Messages
229
Userform: "PTadjustementForm"
Textbox: "PercentNeeded"

I need the value that I input into the form to register in the formula below. I am assuming I need to change the control source on initilizing the form (not exactly sure how to do that) and also creating the percent to be some sort of variable which could be dropped into the formula below (not exactly sure how to do this either)...

**Assume the value I entered into the textbox ("PercentNeeded") was 14%, I would need all the 10% in the formula below replaced:

Code:
Sub PT_Adjustment()
'
Application.ScreenUpdating = False
 
ActiveSheet.PivotTables("PivotTable1").CalculatedFields("base less impl hcd PT" _
        ).StandardFormula = "=Base_pay-(ImpLB1*0.10)-(DLB1*0.10)"
 
ActiveWorkbook.RefreshAll
 
Application.ScreenUpdating = True
End Sub

Thanks for any help
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
In a module in the "general declarations"
Code:
Public MyPercent As Double

in your textbox code
Code:
Private Sub PercentNeeded_Change()
If IsNumeric(Me.PercentNeeded.Value) Then
    
    MyPercent = Me.PercentNeeded.Value
    
    If MyPercent > 1 Then
        MyPercent = MyPercent / 100
    End If
    
End If
End Sub

This is how you would use it into your formula entry

"=Base_pay-(ImpLB1*" & MyPercent & ")-(DLB1*" & MyPercent & ")"
Note quoted blocks and concatenation char &

Code:
Sub PT_Adjustment()
'
Application.ScreenUpdating = False
 
ActiveSheet.PivotTables("PivotTable1").CalculatedFields("base less impl hcd PT" _
        ).StandardFormula = "=Base_pay-(ImpLB1*" & MyPercent & ")-(DLB1*" & MyPercent & ")"
 
ActiveWorkbook.RefreshAll
 
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,407
Messages
6,119,332
Members
448,888
Latest member
Arle8907

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