Apply fixed formula on entry using VBA & Forms

m.hamadeh

New Member
Joined
Jun 14, 2011
Messages
32
Hello team, i have urgent request appreciate if you can help me.

I need to have the my users to apply fixed formula as they enter data in excel cells as following:

1. the user double click a cell in specific range (H2:J30) --> open UserForm1 (text box & command button)
2. user enter a value in text box & click command button
3. active cell value = (value in text box)*G20&" SAR"

thank you,
Mahmoud
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi,

Right click your worksheet tab, view code and paste this code in on the right.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("H2:J30")) Is Nothing Then
Cancel = True
Application.EnableEvents = False
UserForm1.Show
Application.EnableEvents = True
End If
End Sub

Now attach this code to the button on the userform. Note I haven't applied any validation that ensures the value in the textbox is numeric or that the textbox has a value. You may need these.

Code:
Private Sub CommandButton1_Click()
ActiveCell.Value = TextBox1.Text * Range("G20") & " SAR"
Unload Me
End Sub
 
Upvote 0
Hi,

Right click your worksheet tab, view code and paste this code in on the right.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("H2:J30")) Is Nothing Then
Cancel = True
Application.EnableEvents = False
UserForm1.Show
Application.EnableEvents = True
End If
End Sub

Now attach this code to the button on the userform. Note I haven't applied any validation that ensures the value in the textbox is numeric or that the textbox has a value. You may need these.

Code:
Private Sub CommandButton1_Click()
ActiveCell.Value = TextBox1.Text * Range("G20") & " SAR"
Unload Me
End Sub

Perfect worked correct!

Thank you Mike
 
Upvote 0

Forum statistics

Threads
1,213,517
Messages
6,114,085
Members
448,548
Latest member
harryls

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