Select Textbox 1 / set focus on userform when another userform closes

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,738
Office Version
  1. 2007
Platform
  1. Windows
Morning,
I have a userform which is open & there is a command button on this form which opens another userform.
When finished with the second userform i wish to select /add focus on Textbox1 when its closed.

I thought there was an event for when form is closed etc but dont see it.
Example.

Open USERFORM1
Press command button to open USERFORM2
Once finished with USERFORM2 its then closed
It is now i wish for USERFORM1 to be selected / add focuse etc
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi, paste this code in UserForm2:
VBA Code:
Private Sub UserForm_Terminate()
  UserForm1.TextBox1.SetFocus
End Sub
 
Upvote 0
You don't need any code in the second userform. Once it unloads it will return control to whatever routine called it, so just set the focus in the next line after the line that showed the other form.
 
Upvote 0
Considering @RoryA 's wonderful suggestion, this can be an option also. You won't need any code in UserForm2:
VBA Code:
Private Sub CommandButton1_Click()
  UserForm2.Show
  UserForm1.TextBox1.SetFocus
End Sub
 
Upvote 0
Solution
Considering @RoryA 's wonderful suggestion, this can be an option also. You won't need any code in UserForm2:
VBA Code:
Private Sub CommandButton1_Click()
  UserForm2.Show
  UserForm1.TextBox1.SetFocus
End Sub

This worked for me many thanks.
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

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