Populate UserForm Textbox and refresh if cell value changes

03856me

Active Member
Joined
Apr 4, 2008
Messages
297
I have a userform with a textbox whose value comes from a named cell "nextUnitnumber" on worksheet "data". As I add data to the worksheet using the userform the "nextUnitnumber" changes. However, the textbox value on the userform does not refresh.

In my UserForm_Initialize event I am populating the textbox with this code, which works fine:
Code:
Me.txt_unitnumber.Value = Sheets("data").Range("nextUtilnumber").Value

When I execute the code to clear the userform to make ready for the next record I am using the same code with an additional "frm_dataInput.Repaint" command, which does not correctly update from the worksheet value every time, just occasionally.

How do I get the txt_unithumber.Value to refresh EACH time the named cell "nextUnitnumber" value changes without closing the userform and restarting the process?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I moved the frm_dataInput.Repaint command before the
Me.txt_unitnumber.Value = Sheets("data").Range("nextUtilnumber").Value
row but it does nothing - the textbox value remains the same as it was when initialized. It's like it doesn't recognize the cell value has changed even though it has. I could also unload and reload the form to refresh but there are several boxes that the user wants to repeat with each session so that won't work.
 
Upvote 0
Figured it out - I had the following code in the wrong place
Code:
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic

Once I moved the txt_unitnumber.value = code below it, the number refreshed correctly.
 
Upvote 0
Glad you got it! Hopefully it helps someone else in the future.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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