Code can't find value

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
563
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
On my spreadsheet, I have four columns. Headers are in row 1.
A1 = First Name
B1 = Last Name
C1 = Full Name (First Name + " " + Last Name)
D1 = Email Address ((First Name.Last Name@CompanyName.com)

On my form, I have a combo box (cmbMaintPersonnel) that populates with all the names in column C. When the user clicks the submit button, I need to find the name from the combo box from column C. Currently, it does not find anything. "found value = nothing" inside the watches window. Thank you. Here what I have:

VBA Code:
Private Sub btnSubmit_Click()
    Requester = Me.cmbMaintPersonnel.Value
    Worksheets("Maintenance Contact").Activate
    Set found = Worksheets("Maintenance Contact").Range("C2", Range("C" & Rows.Count).End(xlUp)).Find(Requester)
    Unload Me
    frmPurchaseOrder.Show
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Populates Combo box

VBA Code:
Private Sub UserForm_Initialize()
    Me.Caption = "Maintenance Requster"
       
    Dim listLength As Integer
    Dim wks As Worksheet
                
    Set wks = Worksheets("Maintenance Contact")
    listLength = Worksheets("Maintenance Contact").Cells(Rows.Count, "A").End(xlUp).Row '<==== finds the length of the list
    For x = 2 To listLength
        If wks.Cells(x, 3) <> "" Then '<=== ignores the blank spaces
            With cmbMaintPersonnel '<=== name of your comboBox
                .AddItem (wks.Cells(x, 3).Value) '<==== adds it to the list
            End With
        End If
    Next x
    
End Sub
 
Upvote 0
If your happy making the combo two columns (you can hide the 2nd column) & populate it like
VBA Code:
Private Sub UserForm_Initialize()
    Me.Caption = "Maintenance Requster"
       
    Dim listLength As Integer
    Dim wks As Worksheet
                
    Set wks = Worksheets("Maintenance Contact")
    listLength = Worksheets("Maintenance Contact").Cells(Rows.Count, "C").End(xlUp).Row '<==== finds the length of the list
    For x = 2 To listLength
        If wks.Cells(x, 3) <> "" Then '<=== ignores the blank spaces
            With Me.cmbMaintPersonnel '<=== name of your comboBox '<=== name of your comboBox
                .AddItem wks.Cells(x, 3).Value '<==== adds it to the list
                .List(.ListCount - 1, 1) = x
            End With
        End If
    Next x
    
End Sub
you can then use something like
VBA Code:
   With Me.cmbMaintPersonnel
      Rw = .List(.ListIndex, 1)
   End With
which will give you the row that item is on.
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,986
Members
449,058
Latest member
oculus

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