How to display different values to ones entered

jmuzz0630

New Member
Joined
Mar 31, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Good morning all,

I am after some assistance with the following:

Data I enter into my worksheet cells is a 4-digit number which is the vehicle registration number (numbers only, no letters). The data I want displayed in the same cell is the fleet number of the vehicle, not the registation number.

There is approx 100 vehicles that have fleet numbers, so going back & forth trying to correspond the registration number with the fleet number is a time consuming task that has high potential for human error.

I am after a formula or something similar that can assist me, so when I enter the registration number, somehow excel can correspond that rego number with the fleet number, and display the fleet number in that cell.

For example (for this example, Rego 1234 = Fleet 50):
Cell A1, I enter "1234". . I then want Cell A1 to display "50" instead of "1234" without any human input entering "50"...

Does this all make sense, or am I dreaming of such a function??

Thank you in advance!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
What I can think from that you explained is
  • Creating a list and
  • Ideally that list should have 2 components 4 digit number followed by Fleet number - Check column C below 👇
  • Using that list for data validation
Book1
ABC
1NumberFleet NoFinal
21085abcdefgh1085 - abcdefgh
31172bcdefghj1172 - bcdefghj
42661xyzopnm2661 - xyzopnm
53183tryanothert3183 - tryanothert
Sheet1
Cell Formulas
RangeFormula
C2:C5C2=TEXTJOIN(" - ",TRUE,A2:B2)
 
Upvote 0
I would do it this way.
Create a lookup table with all possible registration numbers, with their respective fleet numbers in the adjacent column. Then, add a Worksheet_Change macro to the sheet where you're entering the registration numbers (right-click the sheet tab name, select View Code and place the code in the window that appears on the right of screen). That way, whenever you enter a registration number in column A - it will automatically change to the associated fleet number in the same cell. I would further avoid potential errors by having the cells in column A tied to a validation list - being the list of all possible registration numbers in the lookup table.
Sheet looks like this:
Rego to Fleet number.xlsm
ABCDE
1Rego#Fleet#
2123450
3234550
4345660
5456760
6567870
7678970
8789080
9012380
10
11
12
Sheet1
Cells with Data Validation
CellAllowCriteria
A1:A12List=$D$2:$D$9


Code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Range("A:A"), Target) Is Nothing Then
        On Error GoTo Escape
        Application.EnableEvents = False
        Dim s As String, c As Range
        s = Target
        Set c = Columns("D:D").Find(s)
            If c Is Nothing Then
                MsgBox "Registration not found"
                GoTo Continue
            Else
                Target = c.Offset(0, 1)
            End If
        End If
Continue:
        Application.EnableEvents = True
        Exit Sub
Escape:
        MsgBox "Error " & Err.Number & ": " & Err.Description
        Resume Continue
End Sub

Link to demo file: Rego to Fleet number.xlsm
 
Upvote 0

Forum statistics

Threads
1,215,197
Messages
6,123,585
Members
449,108
Latest member
rache47

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