Range question

Paul15

New Member
Joined
Jun 25, 2020
Messages
44
Office Version
  1. 2019
Platform
  1. Windows
I have the below code in a workbook which works correctly for that workbook. It picks up the entered 3 letter country code from column E, entered by a user in a user form, and then automatically selects the corresponding full nationality from column F.

IE user selects/enters GBR in a combo box on the form, (this information is in my formulas tab column E of the workbook) and the code will automatically select the corresponding full nationality (this in column F of the formulas tab)
GBRUnited Kingdom

I now wish to reuse this code on a different workbook where the column details are
123Smith

The user will select/enter 123, or corresponding staff No and the code will automatically select the staff member by name.

Staff No is combo box Warr and Name is text box Staf1

any help please

VBA Code:
Private Sub docdetails_AfterUpdate()

    Dim myRange As Range, f As Range

    Set myRange = Worksheets("Formulas").Range("E:F")

    Set f = myRange.Find(What:=Warr.Value, LookIn:=xlValues, Lookat:=xlWhole, MatchCase:=False)
    If f Is Nothing Then
        Staf1.Value = ""
    Else
        Staf1.Value = f.Offset(, 1)
    End If


End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Are the staff codes all numbers?
 
Upvote 0
In that case try
VBA Code:
Set f = myRange.Find(What:=Val(Warr.Value), LookIn:=xlValues, Lookat:=xlWhole, MatchCase:=False)
 
Upvote 0

Forum statistics

Threads
1,214,936
Messages
6,122,340
Members
449,079
Latest member
rocketslinger

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