Excel VBA: On Change of an amount on text box from an UserForm to Update onto Excel Worksheet

MissZabrina

New Member
Joined
Feb 18, 2009
Messages
1
Good Morning, I need some directions and ideas on how to write the codes to input data onto certain text boxes, then transfer the input data from the UserForm onto worksheet1. ANy input will be greatly appreicate and making my day!!!

If I have these text boxes: txtE, txtI, txtK.

By clicking the "OK" button "cmdOK" which will check if:

Any change to txtE.value, then the new value will be update onto cell E2 on worksheet1.
Any change to txtI.value, then the new value will be update onto cell I2 on worksheet1.
Any change to txtK.value, then the new value will be update onto cell K2 on worksheet1.

If I only changed the input value on txtE, but no change on txtI & txtK, will only update txtE and do nothing with txtI & txtK. The problem is, I am going to have more than 20 text boxes to do something like that, and I wan to find out a smart way to do this.

So, how do I write an if statement for the "OK" button to just perform the updating only when there is a change of the value on the specific textbox?

Would the codes be something like this? I have no idea...



Sub cmdOK
Sheet("worksheet1").Range("E2").Value = UserForm.txtE.Value.change
Sheet("worksheet1").Range("I2").Value = UserForm.txtI.Value.change
Sheet("worksheet1").Range("K2").Value = UserForm.txtK.Value.change
End Sub​




</PRE>



Thanks a bunch!!!!
Zabrina
<!-- / message -->
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Make a new module. Insert this in it:
Rich (BB code):
Public oldtxtE As String
Public oldtxtI As String
Public oldtxtK As String

In your txtE_Change() code write:
Rich (BB code):
oldtxtE = txtE.Value

Do the same for txtI/txtK.

For the button:
Rich (BB code):
If oldtxtE <> txtE.Value Then
    Worksheets("Sheet1").Range("E2").Value = txtE.Value
End If
Add the same code for txtI/txtK.

What it will do:
The module will declare global variables that can be used in any function.

Whenever you change one of the text boxes, it will store its value in the appropriate variable.

When you click the button, it will check to see if the old value is equal to the current value, and if it's not it will copy to the worksheet.

This is all quite roundabout though. You could do away with the button, and simply make the rowsource for the textboxes equal to the appropriate cells -- any time you change the textbox, the cell would update automatically.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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