Auto Generate

Pestomania

Active Member
Joined
May 30, 2018
Messages
292
Office Version
  1. 365
Platform
  1. Windows
This may be a dumb questions, but any help is appreciated.

I am working with a table that has 3 columns, below is an example:

I am trying to find a way that when "Department" is filled in, the unique code will auto fill with the department abbreviations (vlookup from "Department Abbreviations" tab) and chooses the next unique identifier in the sequence. Everything I do makes it change the numbers when I sort the table which should not happen.

I know Microsoft Access creates the databases with auto numbers that do not change no matter how you sort it. Is there a way to create this in Excel?

DepartmentUnique CodeDescription
FacilitiesFACT-1001Test 1
FacilitiesFACT-1002Test 2
ProductionPROD-1001Test 3
FacilitiesFACT-1003Test 4
 
That is awesome!! I only fixed one thing that it errored on:

End if instead of End With and removed an End If.

VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
    If .Row = 1 Or .Column > 1 Or .Count > 1 Then Exit Sub
        If .Value <> "" Then
            .Offset(0, 1).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-1],Table_Department,2,0)&TEXT(COUNTIF(C1:C1,RC[-1]),""-1000""),""No Match"")"
            .Offset(0, 1).Value = .Offset(0, 1).Value
        Else
            .Offset(0, 1).ClearContents
        End If
  
End With
End Sub
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Is there anyway to turn off the calculated column for only this specific column?
 
Upvote 0
End if instead of End With and removed an End If.
Sorry, I did the edit on my phone, couldn't test it.
Is there anyway to turn off the calculated column for only this specific column?
Not sure what you mean, there is nothing to calculate in the column. If you mean the existing formula(s) then just copy and pastespecial > values. The code overwrites the formula before it ends to prevent calc changes later.
 
Upvote 0
Sorry. It is going into a table in the worksheet so it is using it as a calculated column. But I overrode and told it to turn off calculated column.

So it works great!
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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