How do i use vba code to find a row in a worksheet using listbox index(0) on button click and make the row active?
Worksheet Column A matches listbox index(0) value
Please note that on 14th December 2023 users will experience an expected outage whilst we make upgrades to our network. We anticipate this process may take a couple of hours and so we apologise in advance for any inconvenience.
How do i use vba code to find a row in a worksheet using listbox index(0) on button click and make the row active?
Worksheet Column A matches listbox index(0) value
Your description is very generic so it is not possible to give you code that you can simply plug in.
Where is the ListBox? What is its name? If on a worksheet, is it ActiveX or Forms?
Where is the button? What is its name? If on a worksheet, is it ActiveX or Forms?
What worksheet has the value you want to make active?
Is that worksheet active when you click the button
Something like this:
Public Sub CommandButton1_Click()
Dim Found As Range
Set Found = Worksheet("Sheet 1").Range("A:A").Find(What:=Listbox1.List(0), lookin:=xlValues, lookat:=alWhole)
If Found Is Nothing Then
MsgBox Listbox1.List(0) & " not found in worksheet column A"
Else
Worksheet("Sheet 1").Activate ' may not be necessary if this sheet is already active
Found.Select
End If
End Sub
Display More
6stringJazzer... this works exaclty like I wanted it to! Thank you very much!
Second part of this and I will try to be a little more specific.
The command button executes the code you've provided. I just changed to suit my needs as far as the name of sheet...yaddi yadda.
under the same command button...at the end of this sub... states...userform3.show. This userform is my Customer Order Form
On initialize I have:
but nothing happens
Background on this: Userform 1 is my Customer Activity Center
The listbox has several customers in it. When a customer emails an order... i want to scroll through and find the customer to process the order for.
These customers are identified within this database by their CUSTOMER ID which is the value of the listbox listindex(0) AND the cell value in range ("A") in the worksheet. I thought if someone helped me such as you have with the code to select the cell in range. Then it should be easy to have the cell value go to textbox14 but it has and is evading me. What I want to do is fill Textbox 14 with the value from range A, text box 15 with range B same row, etc., all the way to textbox19 referencing each value in columns A,B,C,D,E. Any help whatsoever? And again, thank you for taking the time for the help with the other code!!
Using ActiveCell is usually not a good idea because the code may not have control over what cell is active. What exactly are you trying to do there?
sorry just saw your reply... been a very busy time for me.
I just need the cell value that has been selected during the subroutine from clicking the command button to be the value that populates textbox14.
the command button is on userform2
textbox14 is on userform3.
selected cell is found by the value in listbx listindex(0). the command button activates worksheet("customers"))...goes through range (A:A) until found, this is the code you suggested to me and it works perfect. Also in the code under the command button it opens my userform3 and upon initliazing I am needing textbox14 to be populated with the selected cells value. I have other textboxes as well but figured once i could figure this part out, i could have the others filled by using the offset.
I hope this gives you enough insight.
Thanks for any help.
Don’t have an account yet? Register yourself now and be a part of our community!