If Textbox has a value Then explanation please

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
Hi
On my userform i have some Textboxes & 2 Listboxes

The Textboxes in question are TextBoxFind & TextBoxReplace

Basically if TextBoxFind has a value in it then set focus on TextBoxReplace

I have this but does nothing.

VBA Code:
Private Sub TextBoxFind_Change()
    TextBoxFind = UCase(TextBoxFind)
    If TextBoxFind.Value > 0 Then
    TextBoxReplace.SetFocus
    End If
End Sub

My understanding which i assume is wrong is that > 0 means anything in the cell ?
Then there is > 1

Ive tried both but still no joy, as you can see in my photo example the value in the Listbox is focused & im looking at setting focus in Textbox.

It works by me typing a value in the the first Textbox,listbox values are shown,a value is selected & placed in Textbox & now i would like the focus set on other Textbox

I see this is the Listbox code but thought after selection was made my Textbox code would overrule it and focus on Textbox.
Rich (BB code):
TextBoxSearchColumnC.SetFocus

EaseUS_2024_11_ 1_10_13_33.jpg
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
A textbox is not a cell. You could use:

VBA Code:
If Len(TextBoxFind.Text) > 0 Then

but I don't really see why you don't just have the listbox code populate the first textbox and set focus to the other textbox.
 
Upvote 0
I wanted it in the Listbox code but codulnt get it to work.

I right clicked ListBox & selected View Code.

I now see the below.
VBA Code:
Private Sub ListBoxFind_Click()
    Me.TextBoxFind.Value = Me.ListBoxFind.List(Me.ListBoxFind.ListIndex)
End Sub

So i then created a change event & added what i thought was correct
But still didnt work for me.
Code:
Private Sub ListBoxFind_Change()
    Me.TextBoxReplace.SetFocus
End Sub
 
Upvote 0
Why not just add that to the Click event code?
 
Upvote 0
Something is happening as when i try you advised code i see the cursor appear in the TextBox but then its gone.
 
Upvote 0
Sounds like you have other code interfering.
 
Upvote 0
I remove all the unwated stuff like close form etc ti minimise code & what was left i went through then pasted it back.
What i was seeing doesnt happen now.

At present i have this in place & works most of the time but now & then it stops & set focus doesnt work.
I did notice when i didnt work sometimes selecting another value in the Listbox got it working again.
But not fully 100% operational

VBA Code:
Private Sub ListBoxFind_Click()
    Me.TextBoxFind.Value = Me.ListBoxFind.List(Me.ListBoxFind.ListIndex)
    Me.TextBoxReplace.SetFocus
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
Members
453,021
Latest member
Justyna P

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