Userform textbox to fill into cell

Garrek

Board Regular
Joined
Aug 22, 2019
Messages
53
Hey all, feeling very dumb here. I'm trying to make a simple userform with one textbox, and when the user hits the "Retire" button it will input the data from the textbox into a specific cell (B14 in my case). This feels very simple and I've done it before, but for some reason I can't get it to work... Case of the Mondays?

Anyway, here's my current code for the box

Code:
Private Sub RetireButton_Click()


Set ssheet = ThisWorkbook.Sheets("New Motifs")


ssheet.Cells(2, 14) = tbCode


Unload Me


End Sub

Eventually I'll also tie to to a macro by using Call after the Unload me, but I can't get this simple thing to work. Any ideas?


EDIT:
Also, should've noted. The textbox is named "Code" and the worksheet it's on is New Motifs. (Figured I'd add, although you should be able to gather it from the code.
 
Last edited by a moderator:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try this:

Code:
Private Sub RetireButton_Click()
    ThisWorkbook.Sheets("New Motifs").Cells(2, 14).value = Code.value
    'ThisWorkbook.Sheets("New Motifs").Cells(2, 14).value = tbCode.value
    Unload Me
End Sub

I've also included a line (which I've commented out for now) which may in fact be the correct fix for you. I know you said that the textbox was named "Code" but because you had already used "tbCode" i wasn't 100% sure.
 
Last edited:
Upvote 0
Try this:

Code:
Private Sub RetireButton_Click()
    ThisWorkbook.Sheets("New Motifs").Cells(2, 14).value = Code.value
    'ThisWorkbook.Sheets("New Motifs").Cells(2, 14).value = tbCode.value
    Unload Me
End Sub

I've also included a line (which I've commented out for now) which may in fact be the correct fix for you. I know you said that the textbox was named "Code" but because you had already used "tbCode" i wasn't 100% sure.


This worked perfectly, thanks a ton! Fresh eyes helped :)
 
Upvote 0

Forum statistics

Threads
1,214,516
Messages
6,119,978
Members
448,934
Latest member
audette89

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