If Textbox has a value Then explanation please

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,731
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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

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