find names value via combobox

hsolanki

Board Regular
Joined
Jan 16, 2020
Messages
204
Office Version
  1. 2010
Platform
  1. Windows
Morning everyone

I have got the code which perfectly working. combobox1 finds the staff number and then populates names in Combobox 1 & 5 however i would like to change this from a staff number to names find

below is the code whereby it finds it using the staff number. the staff number is in column A & names in column B

VBA Code:
Private Sub ComboBox1_Change()

    If Me.ComboBox1.Value <> "" Then
        Me.TextBox1.Value = Application.WorksheetFunction.VLookup(CLng(Me.ComboBox1.Value), ThisWorkbook.Sheets("Monthly Summary").Range("A:B"), 2, 0)
        Me.TextBox6.Value = Application.WorksheetFunction.VLookup(CLng(Me.ComboBox1.Value), ThisWorkbook.Sheets("Monthly Summary").Range("A:C"), 3, 0)
        
    Else
        Me.TextBox1.Value = ""
    End If

End Sub
 
VBA Code:
Private Sub ComboBox1_Change()
    With ThisWorkbook.Sheets("Monthly Summary")
    If Me.ComboBox1.Value <> "" Then
        Me.TextBox1.Value = WorksheetFunction.Vlookup(Me.ComboBox1.Value, .Range("A:C"), 2, 0)
        Me.TextBox6.Value = WorksheetFunction.Vlookup(Me.ComboBox1.Value, .Range("A:C"), 3, 0)
    Else
        Me.TextBox1.Value = ""
        Me.TextBox6.Value = ""
    End If
    End With
End Sub
 
Upvote 0

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
Hi I get an error when I tried the suggested code
 

Attachments

  • 1674726541946.png
    1674726541946.png
    8.6 KB · Views: 6
Upvote 0
I hope this will solve your problem:
VBA Code:
Private Sub ComboBox1_Change()
    With ThisWorkbook.Sheets("Monthly Summary")
    If Me.ComboBox1.Value <> "" Then
        Me.TextBox1.Value = WorksheetFunction.Vlookup(CLng(Me.ComboBox1.Value), .Range("A:C"), 2, 0)
        Me.TextBox6.Value = WorksheetFunction.Vlookup(CLng(Me.ComboBox1.Value), .Range("A:C"), 3, 0)
    Else
        Me.TextBox1.Value = ""
        Me.TextBox6.Value = ""
    End If
    End With
End Sub
 
Upvote 0
Solution
Hi Flash sorry, this is the final code whereby it works now


VBA Code:
Private Sub ComboBox1_Change()

  With ThisWorkbook.Sheets("Monthly Summary")
    If Me.ComboBox1.Value <> "" Then
        Me.TextBox1.Value = .Cells(WorksheetFunction.Match(Me.ComboBox1.Value, .Range("B:B"), 0), 1).Value
        Me.TextBox6.Value = WorksheetFunction.VLookup(Me.ComboBox1.Value, .Range("B:C"), 2, 0) 
    Else
        Me.TextBox1.Value = ""
    End If
    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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