Clear textbox in textbox_change event

Otchoo

New Member
Joined
Jun 24, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a question about a textbox1_change event.

I created an event that when a number is pasted in a textbox, it will lookup the number in a sheet.

But how do i clear the textbox at the end of the event without triggering the event immediately.

Because if i use this code at the end of the private_sub:

Userform1.Textbox1.value = ""

The textbox will go into a infinite loop.

So what i basically want is that paste value in one textbox on a userform.
The routine runs
And clears the textbox at the end of the Routine so i can paste the next value in the textbox
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi,
welcome to forum

Try adding following line at the Top of the change event & see if resolves your issue

VBA Code:
Private Sub TextBox1_Change()
    If Len(Me.TextBox1.Value) = 0 Then Exit Sub

   'rest of code


End Sub

Dave
 
Upvote 0
Hi, please check if below line at the top with in the routine helps.

VBA Code:
Private Sub TextBox1_Change()
If Len(Trim(TextBox1.Text)) = 0 Then Exit Sub
'your code is here...
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,830
Messages
6,121,835
Members
449,051
Latest member
excelquestion515

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