listbox and textbox

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
I have tried to link a listbox item to a value in my textbox see below. Can anyone tell me why this won't work?
VBA Code:
Private Sub Bottom_of_Page_1_Change()

Dim LBox As ListBox
Dim x As Integer
Dim y As Integer

Set LBox = Me.ListBox4
x = 67
y = 61

If LBox = "STD Page 1" Then
  Value = x
  End If
 
If LBox = "STD Page 2" Then
  Value = y
  End If
 
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
If your trying to enter a value in a Textbox and have that value entered into a listbox.
Try this. Otherwise please explain in words what your wanting to achieve

The script runs when you Exit the Textbox
VBA Code:
Private Sub TextBox1_LostFocus()
'Modified  12/14/2020  7:28:12 AM  EST
ListBox1.AddItem TextBox1.Value
End Sub
 
Upvote 0
Sorry i will add a number value in Textbox code that links with the choose on listbox
 
Upvote 0
For example if this

VBA Code:
LBox = "STD Page 1"

then textbox value should be 67
VBA Code:
LBox = "STD Page 2"

then textbox value should be 61
 
Upvote 0
Upvote 0
I'm sorry I still have no ideal what your trying to do.
Do you mean if you enter 12 into TextBox you want
If Listbox says std page 1 that`s = 67
or If Listbox says std page 2 that`s = 61 which needs to show in the textbox for form user to see.
 
Upvote 0
So what is the name of your Listbox
and you
If Listbox says std page 1 that`s = 67
or If Listbox says std page 2 that`s = 61 which needs to show in the textbox for form user to see.
This is beyond my knowledgebase.
I will continue to monitor this thread to see what I can learn.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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