How do I enter a varialbe into a textbox?

CDICKENS

Active Member
Joined
Mar 24, 2002
Messages
498
I have the following macro that returns a number value that I want to enter into a textbox. I can not figure out how to get that information to the textBox.

Here is my macro and the different things I tried are commented out:

Private Sub CommandButton5_Click()

Dim Upsell1 As Range
'Select the cell to be upsell1
UserForm2.Hide
Workbooks("Inventory.xls").Activate
On Error Resume Next
Set Upsell1 = Application.InputBox("Please select the AWINVNUM you want to Upsell.", , , , , , , 8)
If Upsell1 Is Nothing Then Exit Sub 'User pressed Cancel
On Error GoTo 0
UserForm2.Show
''UpsellItem1Box.Value = "Upsell:" & Upsell1
''UpsellItem1Box.Text = "Upsell:" & Upsell1
Workbooks("USER UPLOAD SHEET TEST.xls").Worksheets("Test").Activate
Range("C5").Value = Upsell1
''UserForm2.Show
''Label29.Caption = "Upsell1: " & Upsell1
End Sub

I can successfully enter the variable in a cell but I can not get that value to the textbox.

Any help?

Thanks,

Chuck
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
I know you have to ask those questions. Yes the UpsellItem1Box is in UserForm2 and the code is in userform2 module.

Chuck
 
Upvote 0
Ok, I think I know what the problem is.

Try putting Userform2.Show AFTER you assign the textbox value. Meaning, this worked for me:

<font face=Courier New>
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CommandButton1_Click()
<SPAN style="color:#00007F">Dim</SPAN> Upsell1 <SPAN style="color:#00007F">As</SPAN> Range
<SPAN style="color:#007F00">'Select the cell to be upsell1</SPAN>
UserForm2.Hide
Workbooks("Inventory.xls").Activate
<SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">Resume</SPAN> <SPAN style="color:#00007F">Next</SPAN>
<SPAN style="color:#00007F">Set</SPAN> Upsell1 = Application.InputBox("Please select the AWINVNUM you want to Upsell.", , , , , , , 8)
<SPAN style="color:#00007F">If</SPAN> Upsell1 <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN> <SPAN style="color:#007F00">'User pressed Cancel</SPAN>
<SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> 0
UpsellItem1Box.Value = "Upsell:" & Upsell1
<SPAN style="color:#007F00">''UpsellItem1Box.Text = "Upsell:" & Upsell1</SPAN>
Workbooks("USER UPLOAD SHEET TEST.xls").Worksheets("Test").Activate
Range("C5").Value = Upsell1
<SPAN style="color:#007F00">''Label29.Caption = "Upsell1: " & Upsell1</SPAN>
UserForm2.Show
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 
Upvote 0

Forum statistics

Threads
1,221,711
Messages
6,161,450
Members
451,707
Latest member
PedroMoss2268

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