Selecting a row based on entry in combobox

kuroriposte

New Member
Joined
Jul 23, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi i am looking to select a row in the sheet based on the text value appearing in a combobox from user forms.
Currently i have this code but it selects the entire sheet instead.
Private Sub cmdupdate_Click()
Dim rng As Range
Set rng = Range("A1", Range("A65536").End(xlUp))
For Each cell In rng
If cell.Value = items.Text Then
Rows.Select
End If
Next cell
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Your situation is not clearly expressed.
Are you looking to select only one row ("Hi i am looking to select a row"), or do you want to select all rows that meet your "If cell.Value = items.Text Then" line.

Also, what exactly does items.Text mean. There is no declaration for "items". Maybe it is a String type variable defined as "Hello" so all cells in column A that contain only the word Hello are concomitantly selected, if that is what you want.
 
Upvote 0
Hi, it should technically be a row only, as i do not have any duplicates.
items.text is just the data im pulling from my combobox, its named as items.
 
Upvote 0
Assuming your worksheet of interest is active when the UserForm is called:

Rich (BB code):
Private Sub cmdupdate_Click()
Dim FindWhat$, varFind
FindWhat = items.Value
If FindWhat = "" Then Exit Sub
Set varFind = Colunms(1).Find(What:=FindWhat, LookIn:=xlFormulas, LookAt:=xlWhole)
If Not varFind Is Nothing Then
Rows(varfind.Row).Select
Else
MsgBox FindWhat & " was not found.", 48, "No such animal."
End If
Set varFind = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,701
Messages
6,126,311
Members
449,308
Latest member
Ronaldj

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