Real time textbox update in userform

JohnBi

New Member
Joined
Aug 1, 2016
Messages
31
Office Version
  1. 2019
Platform
  1. Windows
Hello,
in a ws I have cells that are in real time updated.
Now I am able to get the value at the time I read the cell content with:

Dim Title As String
Title = UserForm2.ComboBox1.Value
TextBox2.Value = Application.WorksheetFunction.VLookup(Title, Worksheets("Setup").Range("C2:D115"), 2, False)

Is there a way to see the update value in the userform when the source cell is updated?
Thank you in advance for your help.
Regards
John
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
If you close the userform with Unload this may not work.

In the module for worksheet Setup add this code. This will update the textbox in the user form any time that data in C2:D115 changes.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

   Application.EnableEvents = False
   
   If Not Intersect(Target, Range("C2:D115")) Is Nothing Then
      UserForm2.TextBox2.Value = Application.WorksheetFunction.VLookup(UserForm2.ComboBox1.Value, Range("C2:D115"), 2, False)
   End If

   Application.EnableEvents = True

End Sub
 
Upvote 0
Thank you for your answer.
I change the close code from "Unload Me" to "UserForm2.Hide", but the value of the TextBox2 in still not updated.

Regards
John
 
Upvote 0
I suggest you do some troubleshooting and see if the Worksheet_Change code is executing when expected, and whether the line that updates the textbox is executing when expected. I can test my own code but I can't test it in the context of your file.
 
Upvote 0
How are the cells being updated ? Try the Worksheet_Calculate event and see if that works.
 
Upvote 0
Agree. If C2:D115 contain formulas and you are looking for changes in formula results, the Change event will not do that. You will have to reload the textbox on calculations. But you can't check for the range--so it will be any time there is any calculation.
VBA Code:
Private Sub Worksheet_Calculate()

   Application.EnableEvents = False

   UserForm2.TextBox2.Value = Application.WorksheetFunction.VLookup(UserForm2.ComboBox1.Value, Range("C2:D115"), 2, False)

   Application.EnableEvents = True

End Sub
 
Upvote 0
Hi,
Thank you for all your comments and suggestions. Most likely I'll add a button to refresh manually the userform TextBox2 before insert the value in the sheet.
Regards
John
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,816
Members
449,049
Latest member
cybersurfer5000

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