have userform textbox run macro without using command button

still learning

Well-known Member
Joined
Jan 15, 2010
Messages
821
Office Version
  1. 365
Platform
  1. Windows
Hi
Is there a way to press "enter" after a user types in a name in a text box in a userform to have a macro put that name in a cell.
After, the user will click on a checkbox and a macro will show the user the requested data.
I already made the macro and tested it.

The macros for the checkboxes work good, too

My problem is I don’t know if I can have the macro for the text box work without using a command button

I tried putting the textbox macro in >>>Private Sub TextBox1_Change()<<<

But either I’m using the wrong syntext or it doesn’t go there

If I put the macro in >>>Private Sub CommandButton1_Click()

It works after the command button is pressed

I would like not to have to use the command button
VBA Code:
private Sub CommandButton1_Click()
With TextBox1
ActiveSheet.Range("helpercell").Value = .Text
End With
'End Sub

mike
 

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.
YES! For your TextBox set the ControlSource property to the address of the cell where the data is to be stored.

Below is an example where I did what you are asking with TextBox4 in a UserForm.
(See TextBox4.ControlSource = line of code)
VBA Code:
Private Sub TextBox1_AfterUpdate()
  SearchList
End Sub

Private Sub SearchList()
  Dim rng As Range
  Dim r As Long
  Set rng = ActiveSheet.Range("A5:C16")
  On Error Resume Next
  r = 0
  r = WorksheetFunction.Match(Val(TextBox1), rng.Columns(1), 0)
 
  If r > 0 Then
    Label5 = rng(r, 1)
    Label6 = rng(r, 2)
    TextBox4 = rng(r, 3)
    TextBox4.ControlSource = rng(r, 3).Address
  End If
 
End Sub
 
Upvote 0
Solution
Hi Bosquedeguate
I copied the top part of your code and put it in the textbox1x Sub

I added >>>BZ1 <<< to the controlSource (which is where I want the name to go)

I'm getting at error at
ActiveSheet.Range("helpercell").Value = .Text

the .Text is highlighted and the error message is
"invalid or unqualified reference"

the line works if it's in the command button Sub

I range named BZ1 because I was moving columns around
mike
 
Upvote 0
Hi Bosquedeguate
I copied the top part of your code and put it in the textbox1x Sub

I added >>>BZ1 <<< to the controlSource (which is where I want the name to go)

I'm getting at error at
ActiveSheet.Range("helpercell").Value = .Text

the .Text is highlighted and the error message is
"invalid or unqualified reference"

the line works if it's in the command button Sub

I range named BZ1 because I was moving columns around
mike
Please send all the code

It looks like you might be using a With TextBox clause
End With

And how do you have “helper cell” defined?

I cannot tell what might be the problem from your description.
 
Upvote 0
I started over and remade the userform and put in the command box sub that i was having trouble with when it was in the text box
VBA Code:
Private Sub CommandButton1_Click()
With TextBox1
ActiveSheet.Range("helpercell").Value = .Text
End With
End Sub
I forgot to put in a command button and when I clicked enter, the macro worked...the name went to BZ1
I will play with it some more and come back for more help

Thank you for you patience and help
have a good weekend

mike
 
Upvote 0
I started over and remade the userform and put in the command box sub that i was having trouble with when it was in the text box
VBA Code:
Private Sub CommandButton1_Click()
With TextBox1
ActiveSheet.Range("helpercell").Value = .Text
End With
End Sub
I forgot to put in a command button and when I clicked enter, the macro worked...the name went to BZ1
I will play with it some more and come back for more help

Thank you for you patience and help
have a good weekend

mike
OK you should be able to do the same with the TextBox_Change or TextBox_AfterUpdate events. Setting the ControlSource may or may not be something you need to do. If it is set and will always be the value of fixed cell then the ActiveSheet.Range("helpercell").Value = .Text line of code should not be necessary. Play with it.
 
Upvote 0

Forum statistics

Threads
1,223,157
Messages
6,170,419
Members
452,325
Latest member
BlahQz

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